// Code generated by ent, DO NOT EDIT.

package ent

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

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

// UsageStatisticHour is the model entity for the UsageStatisticHour schema.
type UsageStatisticHour 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 (*UsageStatisticHour) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case usagestatistichour.FieldLabelDist:
			values[i] = new([]byte)
		case usagestatistichour.FieldID, usagestatistichour.FieldStatus, usagestatistichour.FieldAddtime, usagestatistichour.FieldType, usagestatistichour.FieldOrganizationID, usagestatistichour.FieldAiResponse, usagestatistichour.FieldSopRun, usagestatistichour.FieldTotalFriend, usagestatistichour.FieldTotalGroup, usagestatistichour.FieldAccountBalance, usagestatistichour.FieldConsumeToken, usagestatistichour.FieldActiveUser, usagestatistichour.FieldNewUser:
			values[i] = new(sql.NullInt64)
		case usagestatistichour.FieldBotID:
			values[i] = new(sql.NullString)
		case usagestatistichour.FieldCreatedAt, usagestatistichour.FieldUpdatedAt, usagestatistichour.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 UsageStatisticHour fields.
func (ush *UsageStatisticHour) 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 usagestatistichour.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			ush.ID = uint64(value.Int64)
		case usagestatistichour.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 {
				ush.CreatedAt = value.Time
			}
		case usagestatistichour.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 {
				ush.UpdatedAt = value.Time
			}
		case usagestatistichour.FieldStatus:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				ush.Status = uint8(value.Int64)
			}
		case usagestatistichour.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 {
				ush.DeletedAt = value.Time
			}
		case usagestatistichour.FieldAddtime:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field addtime", values[i])
			} else if value.Valid {
				ush.Addtime = uint64(value.Int64)
			}
		case usagestatistichour.FieldType:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field type", values[i])
			} else if value.Valid {
				ush.Type = int(value.Int64)
			}
		case usagestatistichour.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 {
				ush.BotID = value.String
			}
		case usagestatistichour.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 {
				ush.OrganizationID = uint64(value.Int64)
			}
		case usagestatistichour.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 {
				ush.AiResponse = uint64(value.Int64)
			}
		case usagestatistichour.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 {
				ush.SopRun = uint64(value.Int64)
			}
		case usagestatistichour.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 {
				ush.TotalFriend = uint64(value.Int64)
			}
		case usagestatistichour.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 {
				ush.TotalGroup = uint64(value.Int64)
			}
		case usagestatistichour.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 {
				ush.AccountBalance = uint64(value.Int64)
			}
		case usagestatistichour.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 {
				ush.ConsumeToken = uint64(value.Int64)
			}
		case usagestatistichour.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 {
				ush.ActiveUser = uint64(value.Int64)
			}
		case usagestatistichour.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 {
				ush.NewUser = value.Int64
			}
		case usagestatistichour.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, &ush.LabelDist); err != nil {
					return fmt.Errorf("unmarshal field label_dist: %w", err)
				}
			}
		default:
			ush.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

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

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

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

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

// UsageStatisticHours is a parsable slice of UsageStatisticHour.
type UsageStatisticHours []*UsageStatisticHour
