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

	_taskCenterEventLogs.taskCenterEventLogsDo.UseDB(db, opts...)
	_taskCenterEventLogs.taskCenterEventLogsDo.UseModel(&model.TaskCenterEventLogs{})

	tableName := _taskCenterEventLogs.taskCenterEventLogsDo.TableName()
	_taskCenterEventLogs.ALL = field.NewAsterisk(tableName)
	_taskCenterEventLogs.ID = field.NewInt64(tableName, "id")
	_taskCenterEventLogs.EventID = field.NewString(tableName, "event_id")
	_taskCenterEventLogs.SourceType = field.NewString(tableName, "source_type")
	_taskCenterEventLogs.SourceID = field.NewInt64(tableName, "source_id")
	_taskCenterEventLogs.UserID = field.NewInt64(tableName, "user_id")
	_taskCenterEventLogs.TaskID = field.NewInt64(tableName, "task_id")
	_taskCenterEventLogs.TierID = field.NewInt64(tableName, "tier_id")
	_taskCenterEventLogs.IdempotencyKey = field.NewString(tableName, "idempotency_key")
	_taskCenterEventLogs.Status = field.NewString(tableName, "status")
	_taskCenterEventLogs.Result = field.NewString(tableName, "result")
	_taskCenterEventLogs.CreatedAt = field.NewTime(tableName, "created_at")

	_taskCenterEventLogs.fillFieldMap()

	return _taskCenterEventLogs
}

// taskCenterEventLogs 任务中心-事件日志
type taskCenterEventLogs struct {
	taskCenterEventLogsDo

	ALL            field.Asterisk
	ID             field.Int64  // 主键ID
	EventID        field.String // 事件ID（字符串）
	SourceType     field.String // 来源类型：order|invite
	SourceID       field.Int64  // 来源业务ID（订单ID或用户ID）
	UserID         field.Int64  // 用户ID（users.id）
	TaskID         field.Int64  // 任务ID（task_center_tasks.id）
	TierID         field.Int64  // 档位ID（task_center_task_tiers.id）
	IdempotencyKey field.String // 幂等键：user:task:tier:source
	Status         field.String // 处理状态：granted|skipped|rejected
	Result         field.String // 处理结果详情(JSON)
	CreatedAt      field.Time   // 创建时间

	fieldMap map[string]field.Expr
}

func (t taskCenterEventLogs) Table(newTableName string) *taskCenterEventLogs {
	t.taskCenterEventLogsDo.UseTable(newTableName)
	return t.updateTableName(newTableName)
}

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

func (t *taskCenterEventLogs) updateTableName(table string) *taskCenterEventLogs {
	t.ALL = field.NewAsterisk(table)
	t.ID = field.NewInt64(table, "id")
	t.EventID = field.NewString(table, "event_id")
	t.SourceType = field.NewString(table, "source_type")
	t.SourceID = field.NewInt64(table, "source_id")
	t.UserID = field.NewInt64(table, "user_id")
	t.TaskID = field.NewInt64(table, "task_id")
	t.TierID = field.NewInt64(table, "tier_id")
	t.IdempotencyKey = field.NewString(table, "idempotency_key")
	t.Status = field.NewString(table, "status")
	t.Result = field.NewString(table, "result")
	t.CreatedAt = field.NewTime(table, "created_at")

	t.fillFieldMap()

	return t
}

func (t *taskCenterEventLogs) 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 *taskCenterEventLogs) fillFieldMap() {
	t.fieldMap = make(map[string]field.Expr, 11)
	t.fieldMap["id"] = t.ID
	t.fieldMap["event_id"] = t.EventID
	t.fieldMap["source_type"] = t.SourceType
	t.fieldMap["source_id"] = t.SourceID
	t.fieldMap["user_id"] = t.UserID
	t.fieldMap["task_id"] = t.TaskID
	t.fieldMap["tier_id"] = t.TierID
	t.fieldMap["idempotency_key"] = t.IdempotencyKey
	t.fieldMap["status"] = t.Status
	t.fieldMap["result"] = t.Result
	t.fieldMap["created_at"] = t.CreatedAt
}

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

func (t taskCenterEventLogs) replaceDB(db *gorm.DB) taskCenterEventLogs {
	t.taskCenterEventLogsDo.ReplaceDB(db)
	return t
}

type taskCenterEventLogsDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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