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

	_playerBattleDp.playerBattleDpDo.UseDB(db, opts...)
	_playerBattleDp.playerBattleDpDo.UseModel(&model.PlayerBattleDp{})

	tableName := _playerBattleDp.playerBattleDpDo.TableName()
	_playerBattleDp.ALL = field.NewAsterisk(tableName)
	_playerBattleDp.ID = field.NewInt64(tableName, "id")
	_playerBattleDp.Playerid = field.NewInt64(tableName, "playerid")
	_playerBattleDp.DetailsID = field.NewInt64(tableName, "details_id")
	_playerBattleDp.Dps = field.NewFloat64(tableName, "dps")

	_playerBattleDp.fillFieldMap()

	return _playerBattleDp
}

type playerBattleDp struct {
	playerBattleDpDo

	ALL       field.Asterisk
	ID        field.Int64
	Playerid  field.Int64   // 用户ID
	DetailsID field.Int64   // 战斗日志ID
	Dps       field.Float64 // dps

	fieldMap map[string]field.Expr
}

func (p playerBattleDp) Table(newTableName string) *playerBattleDp {
	p.playerBattleDpDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *playerBattleDp) updateTableName(table string) *playerBattleDp {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.Playerid = field.NewInt64(table, "playerid")
	p.DetailsID = field.NewInt64(table, "details_id")
	p.Dps = field.NewFloat64(table, "dps")

	p.fillFieldMap()

	return p
}

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

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

func (p playerBattleDp) replaceDB(db *gorm.DB) playerBattleDp {
	p.playerBattleDpDo.ReplaceDB(db)
	return p
}

type playerBattleDpDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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