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

	_playerDp.playerDpDo.UseDB(db, opts...)
	_playerDp.playerDpDo.UseModel(&model.PlayerDp{})

	tableName := _playerDp.playerDpDo.TableName()
	_playerDp.ALL = field.NewAsterisk(tableName)
	_playerDp.ID = field.NewInt64(tableName, "id")
	_playerDp.Playerid = field.NewInt64(tableName, "playerid")
	_playerDp.Dps = field.NewInt32(tableName, "dps")

	_playerDp.fillFieldMap()

	return _playerDp
}

type playerDp struct {
	playerDpDo

	ALL      field.Asterisk
	ID       field.Int64
	Playerid field.Int64 // 用户ID
	Dps      field.Int32 // dps

	fieldMap map[string]field.Expr
}

func (p playerDp) Table(newTableName string) *playerDp {
	p.playerDpDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *playerDp) updateTableName(table string) *playerDp {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.Playerid = field.NewInt64(table, "playerid")
	p.Dps = field.NewInt32(table, "dps")

	p.fillFieldMap()

	return p
}

func (p *playerDp) 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 *playerDp) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 3)
	p.fieldMap["id"] = p.ID
	p.fieldMap["playerid"] = p.Playerid
	p.fieldMap["dps"] = p.Dps
}

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

func (p playerDp) replaceDB(db *gorm.DB) playerDp {
	p.playerDpDo.ReplaceDB(db)
	return p
}

type playerDpDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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