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

	_taskCenterTasks.taskCenterTasksDo.UseDB(db, opts...)
	_taskCenterTasks.taskCenterTasksDo.UseModel(&model.TaskCenterTasks{})

	tableName := _taskCenterTasks.taskCenterTasksDo.TableName()
	_taskCenterTasks.ALL = field.NewAsterisk(tableName)
	_taskCenterTasks.ID = field.NewInt64(tableName, "id")
	_taskCenterTasks.Name = field.NewString(tableName, "name")
	_taskCenterTasks.Description = field.NewString(tableName, "description")
	_taskCenterTasks.Status = field.NewInt32(tableName, "status")
	_taskCenterTasks.StartTime = field.NewTime(tableName, "start_time")
	_taskCenterTasks.EndTime = field.NewTime(tableName, "end_time")
	_taskCenterTasks.Visibility = field.NewInt32(tableName, "visibility")
	_taskCenterTasks.ConditionsSchema = field.NewString(tableName, "conditions_schema")
	_taskCenterTasks.CreatedAt = field.NewTime(tableName, "created_at")
	_taskCenterTasks.UpdatedAt = field.NewTime(tableName, "updated_at")

	_taskCenterTasks.fillFieldMap()

	return _taskCenterTasks
}

// taskCenterTasks 任务中心-任务
type taskCenterTasks struct {
	taskCenterTasksDo

	ALL              field.Asterisk
	ID               field.Int64  // 主键ID
	Name             field.String // 任务名称
	Description      field.String // 任务描述
	Status           field.Int32  // 任务状态：1启用 0停用
	StartTime        field.Time   // 任务开始时间
	EndTime          field.Time   // 任务结束时间
	Visibility       field.Int32  // 展示开关：1展示 0隐藏
	ConditionsSchema field.String // 规则DSL(JSON)，可选
	CreatedAt        field.Time   // 创建时间
	UpdatedAt        field.Time   // 更新时间

	fieldMap map[string]field.Expr
}

func (t taskCenterTasks) Table(newTableName string) *taskCenterTasks {
	t.taskCenterTasksDo.UseTable(newTableName)
	return t.updateTableName(newTableName)
}

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

func (t *taskCenterTasks) updateTableName(table string) *taskCenterTasks {
	t.ALL = field.NewAsterisk(table)
	t.ID = field.NewInt64(table, "id")
	t.Name = field.NewString(table, "name")
	t.Description = field.NewString(table, "description")
	t.Status = field.NewInt32(table, "status")
	t.StartTime = field.NewTime(table, "start_time")
	t.EndTime = field.NewTime(table, "end_time")
	t.Visibility = field.NewInt32(table, "visibility")
	t.ConditionsSchema = field.NewString(table, "conditions_schema")
	t.CreatedAt = field.NewTime(table, "created_at")
	t.UpdatedAt = field.NewTime(table, "updated_at")

	t.fillFieldMap()

	return t
}

func (t *taskCenterTasks) 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 *taskCenterTasks) fillFieldMap() {
	t.fieldMap = make(map[string]field.Expr, 10)
	t.fieldMap["id"] = t.ID
	t.fieldMap["name"] = t.Name
	t.fieldMap["description"] = t.Description
	t.fieldMap["status"] = t.Status
	t.fieldMap["start_time"] = t.StartTime
	t.fieldMap["end_time"] = t.EndTime
	t.fieldMap["visibility"] = t.Visibility
	t.fieldMap["conditions_schema"] = t.ConditionsSchema
	t.fieldMap["created_at"] = t.CreatedAt
	t.fieldMap["updated_at"] = t.UpdatedAt
}

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

func (t taskCenterTasks) replaceDB(db *gorm.DB) taskCenterTasks {
	t.taskCenterTasksDo.ReplaceDB(db)
	return t
}

type taskCenterTasksDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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