// Code generated by ent, DO NOT EDIT.

package ent

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

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

// UsageTotal is the model entity for the UsageTotal schema.
type UsageTotal 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"`
	// 使用token总数
	TotalTokens uint64 `json:"total_tokens,omitempty"`
	// 重制后的起始usage_detail 索引
	StartIndex uint64 `json:"start_index,omitempty"`
	// usage_detail 索引
	EndIndex uint64 `json:"end_index,omitempty"`
	// 机构 ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	selectValues   sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*UsageTotal) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case usagetotal.FieldID, usagetotal.FieldStatus, usagetotal.FieldType, usagetotal.FieldTotalTokens, usagetotal.FieldStartIndex, usagetotal.FieldEndIndex, usagetotal.FieldOrganizationID:
			values[i] = new(sql.NullInt64)
		case usagetotal.FieldBotID:
			values[i] = new(sql.NullString)
		case usagetotal.FieldCreatedAt, usagetotal.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 UsageTotal fields.
func (ut *UsageTotal) 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 usagetotal.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			ut.ID = uint64(value.Int64)
		case usagetotal.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 {
				ut.CreatedAt = value.Time
			}
		case usagetotal.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 {
				ut.UpdatedAt = value.Time
			}
		case usagetotal.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				ut.Status = uint8(value.Int64)
			}
		case usagetotal.FieldType:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				ut.Type = int(value.Int64)
			}
		case usagetotal.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 {
				ut.BotID = value.String
			}
		case usagetotal.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 {
				ut.TotalTokens = uint64(value.Int64)
			}
		case usagetotal.FieldStartIndex:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field start_index", values[i])
			} else if value.Valid {
				ut.StartIndex = uint64(value.Int64)
			}
		case usagetotal.FieldEndIndex:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field end_index", values[i])
			} else if value.Valid {
				ut.EndIndex = uint64(value.Int64)
			}
		case usagetotal.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 {
				ut.OrganizationID = uint64(value.Int64)
			}
		default:
			ut.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

// Unwrap unwraps the UsageTotal 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 (ut *UsageTotal) Unwrap() *UsageTotal {
	_tx, ok := ut.config.driver.(*txDriver)
	if !ok {
		panic("ent: UsageTotal is not a transactional entity")
	}
	ut.config.driver = _tx.drv
	return ut
}

// String implements the fmt.Stringer.
func (ut *UsageTotal) String() string {
	var builder strings.Builder
	builder.WriteString("UsageTotal(")
	builder.WriteString(fmt.Sprintf("id=%v, ", ut.ID))
	builder.WriteString("created_at=")
	builder.WriteString(ut.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(ut.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", ut.Status))
	builder.WriteString(", ")
	builder.WriteString("type=")
	builder.WriteString(fmt.Sprintf("%v", ut.Type))
	builder.WriteString(", ")
	builder.WriteString("bot_id=")
	builder.WriteString(ut.BotID)
	builder.WriteString(", ")
	builder.WriteString("total_tokens=")
	builder.WriteString(fmt.Sprintf("%v", ut.TotalTokens))
	builder.WriteString(", ")
	builder.WriteString("start_index=")
	builder.WriteString(fmt.Sprintf("%v", ut.StartIndex))
	builder.WriteString(", ")
	builder.WriteString("end_index=")
	builder.WriteString(fmt.Sprintf("%v", ut.EndIndex))
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", ut.OrganizationID))
	builder.WriteByte(')')
	return builder.String()
}

// UsageTotals is a parsable slice of UsageTotal.
type UsageTotals []*UsageTotal
