// 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 dao

import (
	"context"

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

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

	"gorm.io/plugin/dbresolver"

	"bindbox-game/internal/repository/mysql/model"
)

func newTaskCenterUserProgress(db *gorm.DB, opts ...gen.DOOption) taskCenterUserProgress {
	_taskCenterUserProgress := taskCenterUserProgress{}

	_taskCenterUserProgress.taskCenterUserProgressDo.UseDB(db, opts...)
	_taskCenterUserProgress.taskCenterUserProgressDo.UseModel(&model.TaskCenterUserProgress{})

	tableName := _taskCenterUserProgress.taskCenterUserProgressDo.TableName()
	_taskCenterUserProgress.ALL = field.NewAsterisk(tableName)
	_taskCenterUserProgress.ID = field.NewInt64(tableName, "id")
	_taskCenterUserProgress.UserID = field.NewInt64(tableName, "user_id")
	_taskCenterUserProgress.TaskID = field.NewInt64(tableName, "task_id")
	_taskCenterUserProgress.OrderCount = field.NewInt64(tableName, "order_count")
	_taskCenterUserProgress.InviteCount = field.NewInt64(tableName, "invite_count")
	_taskCenterUserProgress.FirstOrder = field.NewInt32(tableName, "first_order")
	_taskCenterUserProgress.ClaimedTiers = field.NewString(tableName, "claimed_tiers")
	_taskCenterUserProgress.CreatedAt = field.NewTime(tableName, "created_at")
	_taskCenterUserProgress.UpdatedAt = field.NewTime(tableName, "updated_at")
	_taskCenterUserProgress.ActivityID = field.NewInt32(tableName, "activity_id")
	_taskCenterUserProgress.OrderAmount = field.NewInt64(tableName, "order_amount")

	_taskCenterUserProgress.fillFieldMap()

	return _taskCenterUserProgress
}

// taskCenterUserProgress 任务中心-用户进度
type taskCenterUserProgress struct {
	taskCenterUserProgressDo

	ALL          field.Asterisk
	ID           field.Int64  // 主键ID
	UserID       field.Int64  // 用户ID（users.id）
	TaskID       field.Int64  // 任务ID（task_center_tasks.id）
	OrderCount   field.Int64  // 累计完成订单数
	InviteCount  field.Int64  // 累计有效邀请数
	FirstOrder   field.Int32  // 首单标记：1是 0否
	ClaimedTiers field.String // 已领取档位ID数组(JSON)
	CreatedAt    field.Time   // 创建时间
	UpdatedAt    field.Time   // 更新时间
	ActivityID   field.Int32
	OrderAmount  field.Int64 // 累计消费金额（单位分）

	fieldMap map[string]field.Expr
}

func (t taskCenterUserProgress) Table(newTableName string) *taskCenterUserProgress {
	t.taskCenterUserProgressDo.UseTable(newTableName)
	return t.updateTableName(newTableName)
}

func (t taskCenterUserProgress) As(alias string) *taskCenterUserProgress {
	t.taskCenterUserProgressDo.DO = *(t.taskCenterUserProgressDo.As(alias).(*gen.DO))
	return t.updateTableName(alias)
}

func (t *taskCenterUserProgress) updateTableName(table string) *taskCenterUserProgress {
	t.ALL = field.NewAsterisk(table)
	t.ID = field.NewInt64(table, "id")
	t.UserID = field.NewInt64(table, "user_id")
	t.TaskID = field.NewInt64(table, "task_id")
	t.OrderCount = field.NewInt64(table, "order_count")
	t.InviteCount = field.NewInt64(table, "invite_count")
	t.FirstOrder = field.NewInt32(table, "first_order")
	t.ClaimedTiers = field.NewString(table, "claimed_tiers")
	t.CreatedAt = field.NewTime(table, "created_at")
	t.UpdatedAt = field.NewTime(table, "updated_at")
	t.ActivityID = field.NewInt32(table, "activity_id")
	t.OrderAmount = field.NewInt64(table, "order_amount")

	t.fillFieldMap()

	return t
}

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

func (t *taskCenterUserProgress) fillFieldMap() {
	t.fieldMap = make(map[string]field.Expr, 11)
	t.fieldMap["id"] = t.ID
	t.fieldMap["user_id"] = t.UserID
	t.fieldMap["task_id"] = t.TaskID
	t.fieldMap["order_count"] = t.OrderCount
	t.fieldMap["invite_count"] = t.InviteCount
	t.fieldMap["first_order"] = t.FirstOrder
	t.fieldMap["claimed_tiers"] = t.ClaimedTiers
	t.fieldMap["created_at"] = t.CreatedAt
	t.fieldMap["updated_at"] = t.UpdatedAt
	t.fieldMap["activity_id"] = t.ActivityID
	t.fieldMap["order_amount"] = t.OrderAmount
}

func (t taskCenterUserProgress) clone(db *gorm.DB) taskCenterUserProgress {
	t.taskCenterUserProgressDo.ReplaceConnPool(db.Statement.ConnPool)
	return t
}

func (t taskCenterUserProgress) replaceDB(db *gorm.DB) taskCenterUserProgress {
	t.taskCenterUserProgressDo.ReplaceDB(db)
	return t
}

type taskCenterUserProgressDo struct{ gen.DO }

func (t taskCenterUserProgressDo) Debug() *taskCenterUserProgressDo {
	return t.withDO(t.DO.Debug())
}

func (t taskCenterUserProgressDo) WithContext(ctx context.Context) *taskCenterUserProgressDo {
	return t.withDO(t.DO.WithContext(ctx))
}

func (t taskCenterUserProgressDo) ReadDB() *taskCenterUserProgressDo {
	return t.Clauses(dbresolver.Read)
}

func (t taskCenterUserProgressDo) WriteDB() *taskCenterUserProgressDo {
	return t.Clauses(dbresolver.Write)
}

func (t taskCenterUserProgressDo) Session(config *gorm.Session) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Session(config))
}

func (t taskCenterUserProgressDo) Clauses(conds ...clause.Expression) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Clauses(conds...))
}

func (t taskCenterUserProgressDo) Returning(value interface{}, columns ...string) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Returning(value, columns...))
}

func (t taskCenterUserProgressDo) Not(conds ...gen.Condition) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Not(conds...))
}

func (t taskCenterUserProgressDo) Or(conds ...gen.Condition) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Or(conds...))
}

func (t taskCenterUserProgressDo) Select(conds ...field.Expr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Select(conds...))
}

func (t taskCenterUserProgressDo) Where(conds ...gen.Condition) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Where(conds...))
}

func (t taskCenterUserProgressDo) Order(conds ...field.Expr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Order(conds...))
}

func (t taskCenterUserProgressDo) Distinct(cols ...field.Expr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Distinct(cols...))
}

func (t taskCenterUserProgressDo) Omit(cols ...field.Expr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Omit(cols...))
}

func (t taskCenterUserProgressDo) Join(table schema.Tabler, on ...field.Expr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Join(table, on...))
}

func (t taskCenterUserProgressDo) LeftJoin(table schema.Tabler, on ...field.Expr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.LeftJoin(table, on...))
}

func (t taskCenterUserProgressDo) RightJoin(table schema.Tabler, on ...field.Expr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.RightJoin(table, on...))
}

func (t taskCenterUserProgressDo) Group(cols ...field.Expr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Group(cols...))
}

func (t taskCenterUserProgressDo) Having(conds ...gen.Condition) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Having(conds...))
}

func (t taskCenterUserProgressDo) Limit(limit int) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Limit(limit))
}

func (t taskCenterUserProgressDo) Offset(offset int) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Offset(offset))
}

func (t taskCenterUserProgressDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Scopes(funcs...))
}

func (t taskCenterUserProgressDo) Unscoped() *taskCenterUserProgressDo {
	return t.withDO(t.DO.Unscoped())
}

func (t taskCenterUserProgressDo) Create(values ...*model.TaskCenterUserProgress) error {
	if len(values) == 0 {
		return nil
	}
	return t.DO.Create(values)
}

func (t taskCenterUserProgressDo) CreateInBatches(values []*model.TaskCenterUserProgress, batchSize int) error {
	return t.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 (t taskCenterUserProgressDo) Save(values ...*model.TaskCenterUserProgress) error {
	if len(values) == 0 {
		return nil
	}
	return t.DO.Save(values)
}

func (t taskCenterUserProgressDo) First() (*model.TaskCenterUserProgress, error) {
	if result, err := t.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.TaskCenterUserProgress), nil
	}
}

func (t taskCenterUserProgressDo) Take() (*model.TaskCenterUserProgress, error) {
	if result, err := t.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.TaskCenterUserProgress), nil
	}
}

func (t taskCenterUserProgressDo) Last() (*model.TaskCenterUserProgress, error) {
	if result, err := t.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.TaskCenterUserProgress), nil
	}
}

func (t taskCenterUserProgressDo) Find() ([]*model.TaskCenterUserProgress, error) {
	result, err := t.DO.Find()
	return result.([]*model.TaskCenterUserProgress), err
}

func (t taskCenterUserProgressDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.TaskCenterUserProgress, err error) {
	buf := make([]*model.TaskCenterUserProgress, 0, batchSize)
	err = t.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 (t taskCenterUserProgressDo) FindInBatches(result *[]*model.TaskCenterUserProgress, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return t.DO.FindInBatches(result, batchSize, fc)
}

func (t taskCenterUserProgressDo) Attrs(attrs ...field.AssignExpr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Attrs(attrs...))
}

func (t taskCenterUserProgressDo) Assign(attrs ...field.AssignExpr) *taskCenterUserProgressDo {
	return t.withDO(t.DO.Assign(attrs...))
}

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

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

func (t taskCenterUserProgressDo) FirstOrInit() (*model.TaskCenterUserProgress, error) {
	if result, err := t.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.TaskCenterUserProgress), nil
	}
}

func (t taskCenterUserProgressDo) FirstOrCreate() (*model.TaskCenterUserProgress, error) {
	if result, err := t.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.TaskCenterUserProgress), nil
	}
}

func (t taskCenterUserProgressDo) FindByPage(offset int, limit int) (result []*model.TaskCenterUserProgress, count int64, err error) {
	result, err = t.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 = t.Offset(-1).Limit(-1).Count()
	return
}

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

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

func (t taskCenterUserProgressDo) Scan(result interface{}) (err error) {
	return t.DO.Scan(result)
}

func (t taskCenterUserProgressDo) Delete(models ...*model.TaskCenterUserProgress) (result gen.ResultInfo, err error) {
	return t.DO.Delete(models)
}

func (t *taskCenterUserProgressDo) withDO(do gen.Dao) *taskCenterUserProgressDo {
	t.DO = *do.(*gen.DO)
	return t
}
