// 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 newTaskCenterTaskRewards(db *gorm.DB, opts ...gen.DOOption) taskCenterTaskRewards {
	_taskCenterTaskRewards := taskCenterTaskRewards{}

	_taskCenterTaskRewards.taskCenterTaskRewardsDo.UseDB(db, opts...)
	_taskCenterTaskRewards.taskCenterTaskRewardsDo.UseModel(&model.TaskCenterTaskRewards{})

	tableName := _taskCenterTaskRewards.taskCenterTaskRewardsDo.TableName()
	_taskCenterTaskRewards.ALL = field.NewAsterisk(tableName)
	_taskCenterTaskRewards.ID = field.NewInt64(tableName, "id")
	_taskCenterTaskRewards.TaskID = field.NewInt64(tableName, "task_id")
	_taskCenterTaskRewards.TierID = field.NewInt64(tableName, "tier_id")
	_taskCenterTaskRewards.RewardType = field.NewString(tableName, "reward_type")
	_taskCenterTaskRewards.RewardPayload = field.NewString(tableName, "reward_payload")
	_taskCenterTaskRewards.Quantity = field.NewInt64(tableName, "quantity")
	_taskCenterTaskRewards.CreatedAt = field.NewTime(tableName, "created_at")
	_taskCenterTaskRewards.UpdatedAt = field.NewTime(tableName, "updated_at")

	_taskCenterTaskRewards.fillFieldMap()

	return _taskCenterTaskRewards
}

// taskCenterTaskRewards 任务中心-奖励配置
type taskCenterTaskRewards struct {
	taskCenterTaskRewardsDo

	ALL           field.Asterisk
	ID            field.Int64  // 主键ID
	TaskID        field.Int64  // 关联任务ID（task_center_tasks.id）
	TierID        field.Int64  // 关联档位ID（task_center_task_tiers.id）
	RewardType    field.String // 奖励类型：points|coupon|item_card|title
	RewardPayload field.String // 奖励载荷(JSON)：各类型所需参数
	Quantity      field.Int64  // 发放数量或上限（视类型）
	CreatedAt     field.Time   // 创建时间
	UpdatedAt     field.Time   // 更新时间

	fieldMap map[string]field.Expr
}

func (t taskCenterTaskRewards) Table(newTableName string) *taskCenterTaskRewards {
	t.taskCenterTaskRewardsDo.UseTable(newTableName)
	return t.updateTableName(newTableName)
}

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

func (t *taskCenterTaskRewards) updateTableName(table string) *taskCenterTaskRewards {
	t.ALL = field.NewAsterisk(table)
	t.ID = field.NewInt64(table, "id")
	t.TaskID = field.NewInt64(table, "task_id")
	t.TierID = field.NewInt64(table, "tier_id")
	t.RewardType = field.NewString(table, "reward_type")
	t.RewardPayload = field.NewString(table, "reward_payload")
	t.Quantity = field.NewInt64(table, "quantity")
	t.CreatedAt = field.NewTime(table, "created_at")
	t.UpdatedAt = field.NewTime(table, "updated_at")

	t.fillFieldMap()

	return t
}

func (t *taskCenterTaskRewards) 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 *taskCenterTaskRewards) fillFieldMap() {
	t.fieldMap = make(map[string]field.Expr, 8)
	t.fieldMap["id"] = t.ID
	t.fieldMap["task_id"] = t.TaskID
	t.fieldMap["tier_id"] = t.TierID
	t.fieldMap["reward_type"] = t.RewardType
	t.fieldMap["reward_payload"] = t.RewardPayload
	t.fieldMap["quantity"] = t.Quantity
	t.fieldMap["created_at"] = t.CreatedAt
	t.fieldMap["updated_at"] = t.UpdatedAt
}

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

func (t taskCenterTaskRewards) replaceDB(db *gorm.DB) taskCenterTaskRewards {
	t.taskCenterTaskRewardsDo.ReplaceDB(db)
	return t
}

type taskCenterTaskRewardsDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

func (t taskCenterTaskRewardsDo) FindByPage(offset int, limit int) (result []*model.TaskCenterTaskRewards, 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 taskCenterTaskRewardsDo) 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 taskCenterTaskRewardsDo) Scan(result interface{}) (err error) {
	return t.DO.Scan(result)
}

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

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