// Code generated by ent, DO NOT EDIT.

package ent

import (
	"encoding/json"
	"fmt"
	"strings"
	"time"
	"wechat-api/ent/custom_types"
	"wechat-api/ent/usagestatisticday"

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

// UsageStatisticDay is the model entity for the UsageStatisticDay schema.
type UsageStatisticDay 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"`
	// Delete Time | 删除日期
	DeletedAt time.Time `json:"deleted_at,omitempty"`
	// 写入年月日
	Addtime uint64 `json:"addtime,omitempty"`
	// 1-微信 2-名片
	Type int `json:"type,omitempty"`
	// 微信或名片id
	BotID string `json:"bot_id,omitempty"`
	// 机构ID
	OrganizationID uint64 `json:"organization_id,omitempty"`
	// AI回复次数
	AiResponse uint64 `json:"ai_response,omitempty"`
	// SOP运行次数
	SopRun uint64 `json:"sop_run,omitempty"`
	// 好友总数
	TotalFriend uint64 `json:"total_friend,omitempty"`
	// 群总数
	TotalGroup uint64 `json:"total_group,omitempty"`
	// 账户余额（单位:分）
	AccountBalance uint64 `json:"account_balance,omitempty"`
	// 消耗token数
	ConsumeToken uint64 `json:"consume_token,omitempty"`
	// 活跃用户数
	ActiveUser uint64 `json:"active_user,omitempty"`
	// 新增用户数
	NewUser int64 `json:"new_user,omitempty"`
	// 标签分布
	LabelDist    []custom_types.LabelDist `json:"label_dist,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*UsageStatisticDay) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case usagestatisticday.FieldLabelDist:
			values[i] = new([]byte)
		case usagestatisticday.FieldID, usagestatisticday.FieldStatus, usagestatisticday.FieldAddtime, usagestatisticday.FieldType, usagestatisticday.FieldOrganizationID, usagestatisticday.FieldAiResponse, usagestatisticday.FieldSopRun, usagestatisticday.FieldTotalFriend, usagestatisticday.FieldTotalGroup, usagestatisticday.FieldAccountBalance, usagestatisticday.FieldConsumeToken, usagestatisticday.FieldActiveUser, usagestatisticday.FieldNewUser:
			values[i] = new(sql.NullInt64)
		case usagestatisticday.FieldBotID:
			values[i] = new(sql.NullString)
		case usagestatisticday.FieldCreatedAt, usagestatisticday.FieldUpdatedAt, usagestatisticday.FieldDeletedAt:
			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 UsageStatisticDay fields.
func (usd *UsageStatisticDay) 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 usagestatisticday.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			usd.ID = uint64(value.Int64)
		case usagestatisticday.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 {
				usd.CreatedAt = value.Time
			}
		case usagestatisticday.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 {
				usd.UpdatedAt = value.Time
			}
		case usagestatisticday.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				usd.Status = uint8(value.Int64)
			}
		case usagestatisticday.FieldDeletedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
			} else if value.Valid {
				usd.DeletedAt = value.Time
			}
		case usagestatisticday.FieldAddtime:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field addtime", values[i])
			} else if value.Valid {
				usd.Addtime = uint64(value.Int64)
			}
		case usagestatisticday.FieldType:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				usd.Type = int(value.Int64)
			}
		case usagestatisticday.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 {
				usd.BotID = value.String
			}
		case usagestatisticday.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 {
				usd.OrganizationID = uint64(value.Int64)
			}
		case usagestatisticday.FieldAiResponse:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field ai_response", values[i])
			} else if value.Valid {
				usd.AiResponse = uint64(value.Int64)
			}
		case usagestatisticday.FieldSopRun:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field sop_run", values[i])
			} else if value.Valid {
				usd.SopRun = uint64(value.Int64)
			}
		case usagestatisticday.FieldTotalFriend:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field total_friend", values[i])
			} else if value.Valid {
				usd.TotalFriend = uint64(value.Int64)
			}
		case usagestatisticday.FieldTotalGroup:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field total_group", values[i])
			} else if value.Valid {
				usd.TotalGroup = uint64(value.Int64)
			}
		case usagestatisticday.FieldAccountBalance:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field account_balance", values[i])
			} else if value.Valid {
				usd.AccountBalance = uint64(value.Int64)
			}
		case usagestatisticday.FieldConsumeToken:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field consume_token", values[i])
			} else if value.Valid {
				usd.ConsumeToken = uint64(value.Int64)
			}
		case usagestatisticday.FieldActiveUser:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field active_user", values[i])
			} else if value.Valid {
				usd.ActiveUser = uint64(value.Int64)
			}
		case usagestatisticday.FieldNewUser:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field new_user", values[i])
			} else if value.Valid {
				usd.NewUser = value.Int64
			}
		case usagestatisticday.FieldLabelDist:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field label_dist", values[i])
			} else if value != nil && len(*value) > 0 {
				if err := json.Unmarshal(*value, &usd.LabelDist); err != nil {
					return fmt.Errorf("unmarshal field label_dist: %w", err)
				}
			}
		default:
			usd.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

// String implements the fmt.Stringer.
func (usd *UsageStatisticDay) String() string {
	var builder strings.Builder
	builder.WriteString("UsageStatisticDay(")
	builder.WriteString(fmt.Sprintf("id=%v, ", usd.ID))
	builder.WriteString("created_at=")
	builder.WriteString(usd.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(usd.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(fmt.Sprintf("%v", usd.Status))
	builder.WriteString(", ")
	builder.WriteString("deleted_at=")
	builder.WriteString(usd.DeletedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("addtime=")
	builder.WriteString(fmt.Sprintf("%v", usd.Addtime))
	builder.WriteString(", ")
	builder.WriteString("type=")
	builder.WriteString(fmt.Sprintf("%v", usd.Type))
	builder.WriteString(", ")
	builder.WriteString("bot_id=")
	builder.WriteString(usd.BotID)
	builder.WriteString(", ")
	builder.WriteString("organization_id=")
	builder.WriteString(fmt.Sprintf("%v", usd.OrganizationID))
	builder.WriteString(", ")
	builder.WriteString("ai_response=")
	builder.WriteString(fmt.Sprintf("%v", usd.AiResponse))
	builder.WriteString(", ")
	builder.WriteString("sop_run=")
	builder.WriteString(fmt.Sprintf("%v", usd.SopRun))
	builder.WriteString(", ")
	builder.WriteString("total_friend=")
	builder.WriteString(fmt.Sprintf("%v", usd.TotalFriend))
	builder.WriteString(", ")
	builder.WriteString("total_group=")
	builder.WriteString(fmt.Sprintf("%v", usd.TotalGroup))
	builder.WriteString(", ")
	builder.WriteString("account_balance=")
	builder.WriteString(fmt.Sprintf("%v", usd.AccountBalance))
	builder.WriteString(", ")
	builder.WriteString("consume_token=")
	builder.WriteString(fmt.Sprintf("%v", usd.ConsumeToken))
	builder.WriteString(", ")
	builder.WriteString("active_user=")
	builder.WriteString(fmt.Sprintf("%v", usd.ActiveUser))
	builder.WriteString(", ")
	builder.WriteString("new_user=")
	builder.WriteString(fmt.Sprintf("%v", usd.NewUser))
	builder.WriteString(", ")
	builder.WriteString("label_dist=")
	builder.WriteString(fmt.Sprintf("%v", usd.LabelDist))
	builder.WriteByte(')')
	return builder.String()
}

// UsageStatisticDays is a parsable slice of UsageStatisticDay.
type UsageStatisticDays []*UsageStatisticDay
