// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.

package query

import (
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"wechat-api/database/dao/wechat/model"
)

func newUsageStatisticDay(db *gorm.DB, opts ...gen.DOOption) usageStatisticDay {
	_usageStatisticDay := usageStatisticDay{}

	_usageStatisticDay.usageStatisticDayDo.UseDB(db, opts...)
	_usageStatisticDay.usageStatisticDayDo.UseModel(&model.UsageStatisticDay{})

	tableName := _usageStatisticDay.usageStatisticDayDo.TableName()
	_usageStatisticDay.ALL = field.NewAsterisk(tableName)
	_usageStatisticDay.ID = field.NewInt64(tableName, "id")
	_usageStatisticDay.CreatedAt = field.NewTime(tableName, "created_at")
	_usageStatisticDay.UpdatedAt = field.NewTime(tableName, "updated_at")
	_usageStatisticDay.Status = field.NewInt64(tableName, "status")
	_usageStatisticDay.DeletedAt = field.NewField(tableName, "deleted_at")
	_usageStatisticDay.Addtime = field.NewInt64(tableName, "addtime")
	_usageStatisticDay.Type = field.NewInt64(tableName, "type")
	_usageStatisticDay.BotID = field.NewString(tableName, "bot_id")
	_usageStatisticDay.OrganizationID = field.NewInt64(tableName, "organization_id")
	_usageStatisticDay.AiResponse = field.NewInt64(tableName, "ai_response")
	_usageStatisticDay.SopRun = field.NewInt64(tableName, "sop_run")
	_usageStatisticDay.TotalFriend = field.NewInt64(tableName, "total_friend")
	_usageStatisticDay.TotalGroup = field.NewInt64(tableName, "total_group")
	_usageStatisticDay.AccountBalance = field.NewInt64(tableName, "account_balance")
	_usageStatisticDay.ConsumeToken = field.NewInt64(tableName, "consume_token")
	_usageStatisticDay.ActiveUser = field.NewInt64(tableName, "active_user")
	_usageStatisticDay.NewUser = field.NewInt64(tableName, "new_user")
	_usageStatisticDay.LabelDist = field.NewString(tableName, "label_dist")

	_usageStatisticDay.fillFieldMap()

	return _usageStatisticDay
}

type usageStatisticDay struct {
	usageStatisticDayDo

	ALL            field.Asterisk
	ID             field.Int64
	CreatedAt      field.Time   // Create Time | 创建日期
	UpdatedAt      field.Time   // Update Time | 修改日期
	Status         field.Int64  // 状态 1 正常 2 禁用
	DeletedAt      field.Field  // Delete Time | 删除日期
	Addtime        field.Int64  // 写入年月日
	Type           field.Int64  // 1-微信 2-名片
	BotID          field.String // 微信或名片id
	OrganizationID field.Int64  // 机构 ID
	AiResponse     field.Int64  // AI回复次数
	SopRun         field.Int64  // SOP运行次数
	TotalFriend    field.Int64  // 好友总数
	TotalGroup     field.Int64  // 群总数
	AccountBalance field.Int64  // 账户余额（单位:分）
	ConsumeToken   field.Int64  // 消耗token数
	ActiveUser     field.Int64  // 活跃用户数
	NewUser        field.Int64  // 新增用户数
	LabelDist      field.String // 标签分布

	fieldMap map[string]field.Expr
}

func (u usageStatisticDay) Table(newTableName string) *usageStatisticDay {
	u.usageStatisticDayDo.UseTable(newTableName)
	return u.updateTableName(newTableName)
}

func (u usageStatisticDay) As(alias string) *usageStatisticDay {
	u.usageStatisticDayDo.DO = *(u.usageStatisticDayDo.As(alias).(*gen.DO))
	return u.updateTableName(alias)
}

func (u *usageStatisticDay) updateTableName(table string) *usageStatisticDay {
	u.ALL = field.NewAsterisk(table)
	u.ID = field.NewInt64(table, "id")
	u.CreatedAt = field.NewTime(table, "created_at")
	u.UpdatedAt = field.NewTime(table, "updated_at")
	u.Status = field.NewInt64(table, "status")
	u.DeletedAt = field.NewField(table, "deleted_at")
	u.Addtime = field.NewInt64(table, "addtime")
	u.Type = field.NewInt64(table, "type")
	u.BotID = field.NewString(table, "bot_id")
	u.OrganizationID = field.NewInt64(table, "organization_id")
	u.AiResponse = field.NewInt64(table, "ai_response")
	u.SopRun = field.NewInt64(table, "sop_run")
	u.TotalFriend = field.NewInt64(table, "total_friend")
	u.TotalGroup = field.NewInt64(table, "total_group")
	u.AccountBalance = field.NewInt64(table, "account_balance")
	u.ConsumeToken = field.NewInt64(table, "consume_token")
	u.ActiveUser = field.NewInt64(table, "active_user")
	u.NewUser = field.NewInt64(table, "new_user")
	u.LabelDist = field.NewString(table, "label_dist")

	u.fillFieldMap()

	return u
}

func (u *usageStatisticDay) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
	_f, ok := u.fieldMap[fieldName]
	if !ok || _f == nil {
		return nil, false
	}
	_oe, ok := _f.(field.OrderExpr)
	return _oe, ok
}

func (u *usageStatisticDay) fillFieldMap() {
	u.fieldMap = make(map[string]field.Expr, 18)
	u.fieldMap["id"] = u.ID
	u.fieldMap["created_at"] = u.CreatedAt
	u.fieldMap["updated_at"] = u.UpdatedAt
	u.fieldMap["status"] = u.Status
	u.fieldMap["deleted_at"] = u.DeletedAt
	u.fieldMap["addtime"] = u.Addtime
	u.fieldMap["type"] = u.Type
	u.fieldMap["bot_id"] = u.BotID
	u.fieldMap["organization_id"] = u.OrganizationID
	u.fieldMap["ai_response"] = u.AiResponse
	u.fieldMap["sop_run"] = u.SopRun
	u.fieldMap["total_friend"] = u.TotalFriend
	u.fieldMap["total_group"] = u.TotalGroup
	u.fieldMap["account_balance"] = u.AccountBalance
	u.fieldMap["consume_token"] = u.ConsumeToken
	u.fieldMap["active_user"] = u.ActiveUser
	u.fieldMap["new_user"] = u.NewUser
	u.fieldMap["label_dist"] = u.LabelDist
}

func (u usageStatisticDay) clone(db *gorm.DB) usageStatisticDay {
	u.usageStatisticDayDo.ReplaceConnPool(db.Statement.ConnPool)
	return u
}

func (u usageStatisticDay) replaceDB(db *gorm.DB) usageStatisticDay {
	u.usageStatisticDayDo.ReplaceDB(db)
	return u
}

type usageStatisticDayDo struct{ gen.DO }

type IUsageStatisticDayDo interface {
	gen.SubQuery
	Debug() IUsageStatisticDayDo
	WithContext(ctx context.Context) IUsageStatisticDayDo
	WithResult(fc func(tx gen.Dao)) gen.ResultInfo
	ReplaceDB(db *gorm.DB)
	ReadDB() IUsageStatisticDayDo
	WriteDB() IUsageStatisticDayDo
	As(alias string) gen.Dao
	Session(config *gorm.Session) IUsageStatisticDayDo
	Columns(cols ...field.Expr) gen.Columns
	Clauses(conds ...clause.Expression) IUsageStatisticDayDo
	Not(conds ...gen.Condition) IUsageStatisticDayDo
	Or(conds ...gen.Condition) IUsageStatisticDayDo
	Select(conds ...field.Expr) IUsageStatisticDayDo
	Where(conds ...gen.Condition) IUsageStatisticDayDo
	Order(conds ...field.Expr) IUsageStatisticDayDo
	Distinct(cols ...field.Expr) IUsageStatisticDayDo
	Omit(cols ...field.Expr) IUsageStatisticDayDo
	Join(table schema.Tabler, on ...field.Expr) IUsageStatisticDayDo
	LeftJoin(table schema.Tabler, on ...field.Expr) IUsageStatisticDayDo
	RightJoin(table schema.Tabler, on ...field.Expr) IUsageStatisticDayDo
	Group(cols ...field.Expr) IUsageStatisticDayDo
	Having(conds ...gen.Condition) IUsageStatisticDayDo
	Limit(limit int) IUsageStatisticDayDo
	Offset(offset int) IUsageStatisticDayDo
	Count() (count int64, err error)
	Scopes(funcs ...func(gen.Dao) gen.Dao) IUsageStatisticDayDo
	Unscoped() IUsageStatisticDayDo
	Create(values ...*model.UsageStatisticDay) error
	CreateInBatches(values []*model.UsageStatisticDay, batchSize int) error
	Save(values ...*model.UsageStatisticDay) error
	First() (*model.UsageStatisticDay, error)
	Take() (*model.UsageStatisticDay, error)
	Last() (*model.UsageStatisticDay, error)
	Find() ([]*model.UsageStatisticDay, error)
	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.UsageStatisticDay, err error)
	FindInBatches(result *[]*model.UsageStatisticDay, batchSize int, fc func(tx gen.Dao, batch int) error) error
	Pluck(column field.Expr, dest interface{}) error
	Delete(...*model.UsageStatisticDay) (info gen.ResultInfo, err error)
	Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	Updates(value interface{}) (info gen.ResultInfo, err error)
	UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
	UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
	UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
	UpdateFrom(q gen.SubQuery) gen.Dao
	Attrs(attrs ...field.AssignExpr) IUsageStatisticDayDo
	Assign(attrs ...field.AssignExpr) IUsageStatisticDayDo
	Joins(fields ...field.RelationField) IUsageStatisticDayDo
	Preload(fields ...field.RelationField) IUsageStatisticDayDo
	FirstOrInit() (*model.UsageStatisticDay, error)
	FirstOrCreate() (*model.UsageStatisticDay, error)
	FindByPage(offset int, limit int) (result []*model.UsageStatisticDay, count int64, err error)
	ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
	Scan(result interface{}) (err error)
	Returning(value interface{}, columns ...string) IUsageStatisticDayDo
	UnderlyingDB() *gorm.DB
	schema.Tabler
}

func (u usageStatisticDayDo) Debug() IUsageStatisticDayDo {
	return u.withDO(u.DO.Debug())
}

func (u usageStatisticDayDo) WithContext(ctx context.Context) IUsageStatisticDayDo {
	return u.withDO(u.DO.WithContext(ctx))
}

func (u usageStatisticDayDo) ReadDB() IUsageStatisticDayDo {
	return u.Clauses(dbresolver.Read)
}

func (u usageStatisticDayDo) WriteDB() IUsageStatisticDayDo {
	return u.Clauses(dbresolver.Write)
}

func (u usageStatisticDayDo) Session(config *gorm.Session) IUsageStatisticDayDo {
	return u.withDO(u.DO.Session(config))
}

func (u usageStatisticDayDo) Clauses(conds ...clause.Expression) IUsageStatisticDayDo {
	return u.withDO(u.DO.Clauses(conds...))
}

func (u usageStatisticDayDo) Returning(value interface{}, columns ...string) IUsageStatisticDayDo {
	return u.withDO(u.DO.Returning(value, columns...))
}

func (u usageStatisticDayDo) Not(conds ...gen.Condition) IUsageStatisticDayDo {
	return u.withDO(u.DO.Not(conds...))
}

func (u usageStatisticDayDo) Or(conds ...gen.Condition) IUsageStatisticDayDo {
	return u.withDO(u.DO.Or(conds...))
}

func (u usageStatisticDayDo) Select(conds ...field.Expr) IUsageStatisticDayDo {
	return u.withDO(u.DO.Select(conds...))
}

func (u usageStatisticDayDo) Where(conds ...gen.Condition) IUsageStatisticDayDo {
	return u.withDO(u.DO.Where(conds...))
}

func (u usageStatisticDayDo) Order(conds ...field.Expr) IUsageStatisticDayDo {
	return u.withDO(u.DO.Order(conds...))
}

func (u usageStatisticDayDo) Distinct(cols ...field.Expr) IUsageStatisticDayDo {
	return u.withDO(u.DO.Distinct(cols...))
}

func (u usageStatisticDayDo) Omit(cols ...field.Expr) IUsageStatisticDayDo {
	return u.withDO(u.DO.Omit(cols...))
}

func (u usageStatisticDayDo) Join(table schema.Tabler, on ...field.Expr) IUsageStatisticDayDo {
	return u.withDO(u.DO.Join(table, on...))
}

func (u usageStatisticDayDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUsageStatisticDayDo {
	return u.withDO(u.DO.LeftJoin(table, on...))
}

func (u usageStatisticDayDo) RightJoin(table schema.Tabler, on ...field.Expr) IUsageStatisticDayDo {
	return u.withDO(u.DO.RightJoin(table, on...))
}

func (u usageStatisticDayDo) Group(cols ...field.Expr) IUsageStatisticDayDo {
	return u.withDO(u.DO.Group(cols...))
}

func (u usageStatisticDayDo) Having(conds ...gen.Condition) IUsageStatisticDayDo {
	return u.withDO(u.DO.Having(conds...))
}

func (u usageStatisticDayDo) Limit(limit int) IUsageStatisticDayDo {
	return u.withDO(u.DO.Limit(limit))
}

func (u usageStatisticDayDo) Offset(offset int) IUsageStatisticDayDo {
	return u.withDO(u.DO.Offset(offset))
}

func (u usageStatisticDayDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUsageStatisticDayDo {
	return u.withDO(u.DO.Scopes(funcs...))
}

func (u usageStatisticDayDo) Unscoped() IUsageStatisticDayDo {
	return u.withDO(u.DO.Unscoped())
}

func (u usageStatisticDayDo) Create(values ...*model.UsageStatisticDay) error {
	if len(values) == 0 {
		return nil
	}
	return u.DO.Create(values)
}

func (u usageStatisticDayDo) CreateInBatches(values []*model.UsageStatisticDay, batchSize int) error {
	return u.DO.CreateInBatches(values, batchSize)
}

// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (u usageStatisticDayDo) Save(values ...*model.UsageStatisticDay) error {
	if len(values) == 0 {
		return nil
	}
	return u.DO.Save(values)
}

func (u usageStatisticDayDo) First() (*model.UsageStatisticDay, error) {
	if result, err := u.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.UsageStatisticDay), nil
	}
}

func (u usageStatisticDayDo) Take() (*model.UsageStatisticDay, error) {
	if result, err := u.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.UsageStatisticDay), nil
	}
}

func (u usageStatisticDayDo) Last() (*model.UsageStatisticDay, error) {
	if result, err := u.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.UsageStatisticDay), nil
	}
}

func (u usageStatisticDayDo) Find() ([]*model.UsageStatisticDay, error) {
	result, err := u.DO.Find()
	return result.([]*model.UsageStatisticDay), err
}

func (u usageStatisticDayDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.UsageStatisticDay, err error) {
	buf := make([]*model.UsageStatisticDay, 0, batchSize)
	err = u.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
		defer func() { results = append(results, buf...) }()
		return fc(tx, batch)
	})
	return results, err
}

func (u usageStatisticDayDo) FindInBatches(result *[]*model.UsageStatisticDay, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return u.DO.FindInBatches(result, batchSize, fc)
}

func (u usageStatisticDayDo) Attrs(attrs ...field.AssignExpr) IUsageStatisticDayDo {
	return u.withDO(u.DO.Attrs(attrs...))
}

func (u usageStatisticDayDo) Assign(attrs ...field.AssignExpr) IUsageStatisticDayDo {
	return u.withDO(u.DO.Assign(attrs...))
}

func (u usageStatisticDayDo) Joins(fields ...field.RelationField) IUsageStatisticDayDo {
	for _, _f := range fields {
		u = *u.withDO(u.DO.Joins(_f))
	}
	return &u
}

func (u usageStatisticDayDo) Preload(fields ...field.RelationField) IUsageStatisticDayDo {
	for _, _f := range fields {
		u = *u.withDO(u.DO.Preload(_f))
	}
	return &u
}

func (u usageStatisticDayDo) FirstOrInit() (*model.UsageStatisticDay, error) {
	if result, err := u.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.UsageStatisticDay), nil
	}
}

func (u usageStatisticDayDo) FirstOrCreate() (*model.UsageStatisticDay, error) {
	if result, err := u.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.UsageStatisticDay), nil
	}
}

func (u usageStatisticDayDo) FindByPage(offset int, limit int) (result []*model.UsageStatisticDay, count int64, err error) {
	result, err = u.Offset(offset).Limit(limit).Find()
	if err != nil {
		return
	}

	if size := len(result); 0 < limit && 0 < size && size < limit {
		count = int64(size + offset)
		return
	}

	count, err = u.Offset(-1).Limit(-1).Count()
	return
}

func (u usageStatisticDayDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
	count, err = u.Count()
	if err != nil {
		return
	}

	err = u.Offset(offset).Limit(limit).Scan(result)
	return
}

func (u usageStatisticDayDo) Scan(result interface{}) (err error) {
	return u.DO.Scan(result)
}

func (u usageStatisticDayDo) Delete(models ...*model.UsageStatisticDay) (result gen.ResultInfo, err error) {
	return u.DO.Delete(models)
}

func (u *usageStatisticDayDo) withDO(do gen.Dao) *usageStatisticDayDo {
	u.DO = *do.(*gen.DO)
	return u
}
