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

	"gadmin/internal/gorm/model"
)

func newPlayerDayTask(db *gorm.DB, opts ...gen.DOOption) playerDayTask {
	_playerDayTask := playerDayTask{}

	_playerDayTask.playerDayTaskDo.UseDB(db, opts...)
	_playerDayTask.playerDayTaskDo.UseModel(&model.PlayerDayTask{})

	tableName := _playerDayTask.playerDayTaskDo.TableName()
	_playerDayTask.ALL = field.NewAsterisk(tableName)
	_playerDayTask.ID = field.NewInt64(tableName, "id")
	_playerDayTask.Playerid = field.NewInt64(tableName, "playerid")
	_playerDayTask.Day = field.NewString(tableName, "day")
	_playerDayTask.Process = field.NewInt32(tableName, "process")
	_playerDayTask.Tasks = field.NewString(tableName, "tasks")
	_playerDayTask.Awards = field.NewString(tableName, "awards")
	_playerDayTask.Novice = field.NewString(tableName, "novice")
	_playerDayTask.Pass = field.NewString(tableName, "pass")

	_playerDayTask.fillFieldMap()

	return _playerDayTask
}

type playerDayTask struct {
	playerDayTaskDo

	ALL      field.Asterisk
	ID       field.Int64
	Playerid field.Int64
	Day      field.String
	Process  field.Int32
	Tasks    field.String
	Awards   field.String
	Novice   field.String
	Pass     field.String

	fieldMap map[string]field.Expr
}

func (p playerDayTask) Table(newTableName string) *playerDayTask {
	p.playerDayTaskDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

func (p playerDayTask) As(alias string) *playerDayTask {
	p.playerDayTaskDo.DO = *(p.playerDayTaskDo.As(alias).(*gen.DO))
	return p.updateTableName(alias)
}

func (p *playerDayTask) updateTableName(table string) *playerDayTask {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.Playerid = field.NewInt64(table, "playerid")
	p.Day = field.NewString(table, "day")
	p.Process = field.NewInt32(table, "process")
	p.Tasks = field.NewString(table, "tasks")
	p.Awards = field.NewString(table, "awards")
	p.Novice = field.NewString(table, "novice")
	p.Pass = field.NewString(table, "pass")

	p.fillFieldMap()

	return p
}

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

func (p *playerDayTask) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 8)
	p.fieldMap["id"] = p.ID
	p.fieldMap["playerid"] = p.Playerid
	p.fieldMap["day"] = p.Day
	p.fieldMap["process"] = p.Process
	p.fieldMap["tasks"] = p.Tasks
	p.fieldMap["awards"] = p.Awards
	p.fieldMap["novice"] = p.Novice
	p.fieldMap["pass"] = p.Pass
}

func (p playerDayTask) clone(db *gorm.DB) playerDayTask {
	p.playerDayTaskDo.ReplaceConnPool(db.Statement.ConnPool)
	return p
}

func (p playerDayTask) replaceDB(db *gorm.DB) playerDayTask {
	p.playerDayTaskDo.ReplaceDB(db)
	return p
}

type playerDayTaskDo struct{ gen.DO }

func (p playerDayTaskDo) Debug() *playerDayTaskDo {
	return p.withDO(p.DO.Debug())
}

func (p playerDayTaskDo) WithContext(ctx context.Context) *playerDayTaskDo {
	return p.withDO(p.DO.WithContext(ctx))
}

func (p playerDayTaskDo) ReadDB() *playerDayTaskDo {
	return p.Clauses(dbresolver.Read)
}

func (p playerDayTaskDo) WriteDB() *playerDayTaskDo {
	return p.Clauses(dbresolver.Write)
}

func (p playerDayTaskDo) Session(config *gorm.Session) *playerDayTaskDo {
	return p.withDO(p.DO.Session(config))
}

func (p playerDayTaskDo) Clauses(conds ...clause.Expression) *playerDayTaskDo {
	return p.withDO(p.DO.Clauses(conds...))
}

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

func (p playerDayTaskDo) Not(conds ...gen.Condition) *playerDayTaskDo {
	return p.withDO(p.DO.Not(conds...))
}

func (p playerDayTaskDo) Or(conds ...gen.Condition) *playerDayTaskDo {
	return p.withDO(p.DO.Or(conds...))
}

func (p playerDayTaskDo) Select(conds ...field.Expr) *playerDayTaskDo {
	return p.withDO(p.DO.Select(conds...))
}

func (p playerDayTaskDo) Where(conds ...gen.Condition) *playerDayTaskDo {
	return p.withDO(p.DO.Where(conds...))
}

func (p playerDayTaskDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *playerDayTaskDo {
	return p.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}

func (p playerDayTaskDo) Order(conds ...field.Expr) *playerDayTaskDo {
	return p.withDO(p.DO.Order(conds...))
}

func (p playerDayTaskDo) Distinct(cols ...field.Expr) *playerDayTaskDo {
	return p.withDO(p.DO.Distinct(cols...))
}

func (p playerDayTaskDo) Omit(cols ...field.Expr) *playerDayTaskDo {
	return p.withDO(p.DO.Omit(cols...))
}

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

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

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

func (p playerDayTaskDo) Group(cols ...field.Expr) *playerDayTaskDo {
	return p.withDO(p.DO.Group(cols...))
}

func (p playerDayTaskDo) Having(conds ...gen.Condition) *playerDayTaskDo {
	return p.withDO(p.DO.Having(conds...))
}

func (p playerDayTaskDo) Limit(limit int) *playerDayTaskDo {
	return p.withDO(p.DO.Limit(limit))
}

func (p playerDayTaskDo) Offset(offset int) *playerDayTaskDo {
	return p.withDO(p.DO.Offset(offset))
}

func (p playerDayTaskDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *playerDayTaskDo {
	return p.withDO(p.DO.Scopes(funcs...))
}

func (p playerDayTaskDo) Unscoped() *playerDayTaskDo {
	return p.withDO(p.DO.Unscoped())
}

func (p playerDayTaskDo) Create(values ...*model.PlayerDayTask) error {
	if len(values) == 0 {
		return nil
	}
	return p.DO.Create(values)
}

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

func (p playerDayTaskDo) First() (*model.PlayerDayTask, error) {
	if result, err := p.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerDayTask), nil
	}
}

func (p playerDayTaskDo) Take() (*model.PlayerDayTask, error) {
	if result, err := p.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerDayTask), nil
	}
}

func (p playerDayTaskDo) Last() (*model.PlayerDayTask, error) {
	if result, err := p.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerDayTask), nil
	}
}

func (p playerDayTaskDo) Find() ([]*model.PlayerDayTask, error) {
	result, err := p.DO.Find()
	return result.([]*model.PlayerDayTask), err
}

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

func (p playerDayTaskDo) Attrs(attrs ...field.AssignExpr) *playerDayTaskDo {
	return p.withDO(p.DO.Attrs(attrs...))
}

func (p playerDayTaskDo) Assign(attrs ...field.AssignExpr) *playerDayTaskDo {
	return p.withDO(p.DO.Assign(attrs...))
}

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

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

func (p playerDayTaskDo) FirstOrInit() (*model.PlayerDayTask, error) {
	if result, err := p.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerDayTask), nil
	}
}

func (p playerDayTaskDo) FirstOrCreate() (*model.PlayerDayTask, error) {
	if result, err := p.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerDayTask), nil
	}
}

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

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

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

func (p playerDayTaskDo) Scan(result interface{}) (err error) {
	return p.DO.Scan(result)
}

func (p playerDayTaskDo) Delete(models ...*model.PlayerDayTask) (result gen.ResultInfo, err error) {
	return p.DO.Delete(models)
}

func (p *playerDayTaskDo) withDO(do gen.Dao) *playerDayTaskDo {
	p.DO = *do.(*gen.DO)
	return p
}
