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

	_playerDivination.playerDivinationDo.UseDB(db, opts...)
	_playerDivination.playerDivinationDo.UseModel(&model.PlayerDivination{})

	tableName := _playerDivination.playerDivinationDo.TableName()
	_playerDivination.ALL = field.NewAsterisk(tableName)
	_playerDivination.Playerid = field.NewInt64(tableName, "playerid")
	_playerDivination.DvnStatis = field.NewString(tableName, "dvnStatis")
	_playerDivination.DvnBuff = field.NewString(tableName, "dvnBuff")

	_playerDivination.fillFieldMap()

	return _playerDivination
}

type playerDivination struct {
	playerDivinationDo

	ALL       field.Asterisk
	Playerid  field.Int64
	DvnStatis field.String
	DvnBuff   field.String

	fieldMap map[string]field.Expr
}

func (p playerDivination) Table(newTableName string) *playerDivination {
	p.playerDivinationDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *playerDivination) updateTableName(table string) *playerDivination {
	p.ALL = field.NewAsterisk(table)
	p.Playerid = field.NewInt64(table, "playerid")
	p.DvnStatis = field.NewString(table, "dvnStatis")
	p.DvnBuff = field.NewString(table, "dvnBuff")

	p.fillFieldMap()

	return p
}

func (p *playerDivination) 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 *playerDivination) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 3)
	p.fieldMap["playerid"] = p.Playerid
	p.fieldMap["dvnStatis"] = p.DvnStatis
	p.fieldMap["dvnBuff"] = p.DvnBuff
}

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

func (p playerDivination) replaceDB(db *gorm.DB) playerDivination {
	p.playerDivinationDo.ReplaceDB(db)
	return p
}

type playerDivinationDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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