// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"
	"wechat-api/ent/usagedetail"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
)

// UsageDetail is the model entity for the UsageDetail schema.
type UsageDetail struct {
	config `json:"-"`
	// ID of the ent.
	ID uint64 `json:"id,omitempty"`
	// Create Time | 创建日期
	CreatedAt time.Time `json:"created_at,omitempty"`
	// Update Time | 修改日期
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// Status 1: normal 2: ban | 状态 1 正常 2 禁用
	Status uint8 `json:"status,omitempty"`
	// 1 微信 2 名片
	Type int `json:"type,omitempty"`
	// 微信或名片id
	BotID string `json:"bot_id,omitempty"`
	// 微信id或open_id
	ReceiverID string `json:"receiver_id,omitempty"`
	// 1 cow-basic 2 cow-agent 3 cow-sop 4 mp-card 5 mp-employee
	App int `json:"app,omitempty"`
	// 名片会话id
	SessionID uint64 `json:"session_id,omitempty"`
	// 请求内容
	Request string `json:"request,omitempty"`
	// 响应内容
	Response string `json:"response,omitempty"`
	// 使用token总数
	TotalTokens uint64 `json:"total_tokens,omitempty"`
	// 请求token数
	PromptTokens uint64 `json:"prompt_tokens,omitempty"`
	// 响应token数
	CompletionTokens uint64 `json:"completion_tokens,omitempty"`
	// 机构 ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	selectValues   sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*UsageDetail) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case usagedetail.FieldID, usagedetail.FieldStatus, usagedetail.FieldType, usagedetail.FieldApp, usagedetail.FieldSessionID, usagedetail.FieldTotalTokens, usagedetail.FieldPromptTokens, usagedetail.FieldCompletionTokens, usagedetail.FieldOrganizationID:
			values[i] = new(sql.NullInt64)
		case usagedetail.FieldBotID, usagedetail.FieldReceiverID, usagedetail.FieldRequest, usagedetail.FieldResponse:
			values[i] = new(sql.NullString)
		case usagedetail.FieldCreatedAt, usagedetail.FieldUpdatedAt:
			values[i] = new(sql.NullTime)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the UsageDetail fields.
func (ud *UsageDetail) assignValues(columns []string, values []any) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case usagedetail.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			ud.ID = uint64(value.Int64)
		case usagedetail.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field created_at", values[i])
			} else if value.Valid {
				ud.CreatedAt = value.Time
			}
		case usagedetail.FieldUpdatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
			} else if value.Valid {
				ud.UpdatedAt = value.Time
			}
		case usagedetail.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				ud.Status = uint8(value.Int64)
			}
		case usagedetail.FieldType:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				ud.Type = int(value.Int64)
			}
		case usagedetail.FieldBotID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field bot_id", values[i])
			} else if value.Valid {
				ud.BotID = value.String
			}
		case usagedetail.FieldReceiverID:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field receiver_id", values[i])
			} else if value.Valid {
				ud.ReceiverID = value.String
			}
		case usagedetail.FieldApp:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field app", values[i])
			} else if value.Valid {
				ud.App = int(value.Int64)
			}
		case usagedetail.FieldSessionID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field session_id", values[i])
			} else if value.Valid {
				ud.SessionID = uint64(value.Int64)
			}
		case usagedetail.FieldRequest:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field request", values[i])
			} else if value.Valid {
				ud.Request = value.String
			}
		case usagedetail.FieldResponse:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field response", values[i])
			} else if value.Valid {
				ud.Response = value.String
			}
		case usagedetail.FieldTotalTokens:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field total_tokens", values[i])
			} else if value.Valid {
				ud.TotalTokens = uint64(value.Int64)
			}
		case usagedetail.FieldPromptTokens:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field prompt_tokens", values[i])
			} else if value.Valid {
				ud.PromptTokens = uint64(value.Int64)
			}
		case usagedetail.FieldCompletionTokens:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field completion_tokens", values[i])
			} else if value.Valid {
				ud.CompletionTokens = uint64(value.Int64)
			}
		case usagedetail.FieldOrganizationID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field organization_id", values[i])
			} else if value.Valid {
				ud.OrganizationID = uint64(value.Int64)
			}
		default:
			ud.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the UsageDetail.
// This includes values selected through modifiers, order, etc.
func (ud *UsageDetail) Value(name string) (ent.Value, error) {
	return ud.selectValues.Get(name)
}

// Update returns a builder for updating this UsageDetail.
// Note that you need to call UsageDetail.Unwrap() before calling this method if this UsageDetail
// was returned from a transaction, and the transaction was committed or rolled back.
func (ud *UsageDetail) Update() *UsageDetailUpdateOne {
	return NewUsageDetailClient(ud.config).UpdateOne(ud)
}

// Unwrap unwraps the UsageDetail entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (ud *UsageDetail) Unwrap() *UsageDetail {
	_tx, ok := ud.config.driver.(*txDriver)
	if !ok {
		panic("ent: UsageDetail is not a transactional entity")
	}
	ud.config.driver = _tx.drv
	return ud
}

// String implements the fmt.Stringer.
func (ud *UsageDetail) String() string {
	var builder strings.Builder
	builder.WriteString("UsageDetail(")
	builder.WriteString(fmt.Sprintf("id=%v, ", ud.ID))
	builder.WriteString("created_at=")
	builder.WriteString(ud.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(ud.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", ud.Status))
	builder.WriteString(", ")
	builder.WriteString("type=")
	builder.WriteString(fmt.Sprintf("%v", ud.Type))
	builder.WriteString(", ")
	builder.WriteString("bot_id=")
	builder.WriteString(ud.BotID)
	builder.WriteString(", ")
	builder.WriteString("receiver_id=")
	builder.WriteString(ud.ReceiverID)
	builder.WriteString(", ")
	builder.WriteString("app=")
	builder.WriteString(fmt.Sprintf("%v", ud.App))
	builder.WriteString(", ")
	builder.WriteString("session_id=")
	builder.WriteString(fmt.Sprintf("%v", ud.SessionID))
	builder.WriteString(", ")
	builder.WriteString("request=")
	builder.WriteString(ud.Request)
	builder.WriteString(", ")
	builder.WriteString("response=")
	builder.WriteString(ud.Response)
	builder.WriteString(", ")
	builder.WriteString("total_tokens=")
	builder.WriteString(fmt.Sprintf("%v", ud.TotalTokens))
	builder.WriteString(", ")
	builder.WriteString("prompt_tokens=")
	builder.WriteString(fmt.Sprintf("%v", ud.PromptTokens))
	builder.WriteString(", ")
	builder.WriteString("completion_tokens=")
	builder.WriteString(fmt.Sprintf("%v", ud.CompletionTokens))
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", ud.OrganizationID))
	builder.WriteByte(')')
	return builder.String()
}

// UsageDetails is a parsable slice of UsageDetail.
type UsageDetails []*UsageDetail
