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

	_playerMaterial.playerMaterialDo.UseDB(db, opts...)
	_playerMaterial.playerMaterialDo.UseModel(&model.PlayerMaterial{})

	tableName := _playerMaterial.playerMaterialDo.TableName()
	_playerMaterial.ALL = field.NewAsterisk(tableName)
	_playerMaterial.ID = field.NewInt64(tableName, "id")
	_playerMaterial.Playerid = field.NewInt64(tableName, "playerid")
	_playerMaterial.Coin = field.NewInt64(tableName, "coin")
	_playerMaterial.Diamond = field.NewInt32(tableName, "diamond")
	_playerMaterial.PayCount = field.NewInt32(tableName, "payCount")
	_playerMaterial.Equipments = field.NewString(tableName, "equipments")
	_playerMaterial.FastEquips = field.NewString(tableName, "fastEquips")
	_playerMaterial.Materials = field.NewString(tableName, "materials")
	_playerMaterial.Roles = field.NewString(tableName, "roles")
	_playerMaterial.Talents = field.NewString(tableName, "talents")
	_playerMaterial.PassRoom = field.NewString(tableName, "passRoom")
	_playerMaterial.RoleRes = field.NewString(tableName, "roleRes")
	_playerMaterial.BuffMaterials = field.NewString(tableName, "buffMaterials")
	_playerMaterial.AdLimit = field.NewString(tableName, "adLimit")
	_playerMaterial.Body = field.NewString(tableName, "body")
	_playerMaterial.BroadTrigger = field.NewString(tableName, "broadTrigger")
	_playerMaterial.Treasures = field.NewString(tableName, "treasures")
	_playerMaterial.RoleCollocate = field.NewString(tableName, "roleCollocate")
	_playerMaterial.PaySwitch = field.NewInt32(tableName, "paySwitch")
	_playerMaterial.EquipHistory = field.NewString(tableName, "equipHistory")

	_playerMaterial.fillFieldMap()

	return _playerMaterial
}

type playerMaterial struct {
	playerMaterialDo

	ALL           field.Asterisk
	ID            field.Int64
	Playerid      field.Int64
	Coin          field.Int64
	Diamond       field.Int32
	PayCount      field.Int32
	Equipments    field.String
	FastEquips    field.String
	Materials     field.String
	Roles         field.String
	Talents       field.String
	PassRoom      field.String
	RoleRes       field.String
	BuffMaterials field.String
	AdLimit       field.String
	Body          field.String
	BroadTrigger  field.String
	Treasures     field.String
	RoleCollocate field.String
	PaySwitch     field.Int32
	EquipHistory  field.String

	fieldMap map[string]field.Expr
}

func (p playerMaterial) Table(newTableName string) *playerMaterial {
	p.playerMaterialDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *playerMaterial) updateTableName(table string) *playerMaterial {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.Playerid = field.NewInt64(table, "playerid")
	p.Coin = field.NewInt64(table, "coin")
	p.Diamond = field.NewInt32(table, "diamond")
	p.PayCount = field.NewInt32(table, "payCount")
	p.Equipments = field.NewString(table, "equipments")
	p.FastEquips = field.NewString(table, "fastEquips")
	p.Materials = field.NewString(table, "materials")
	p.Roles = field.NewString(table, "roles")
	p.Talents = field.NewString(table, "talents")
	p.PassRoom = field.NewString(table, "passRoom")
	p.RoleRes = field.NewString(table, "roleRes")
	p.BuffMaterials = field.NewString(table, "buffMaterials")
	p.AdLimit = field.NewString(table, "adLimit")
	p.Body = field.NewString(table, "body")
	p.BroadTrigger = field.NewString(table, "broadTrigger")
	p.Treasures = field.NewString(table, "treasures")
	p.RoleCollocate = field.NewString(table, "roleCollocate")
	p.PaySwitch = field.NewInt32(table, "paySwitch")
	p.EquipHistory = field.NewString(table, "equipHistory")

	p.fillFieldMap()

	return p
}

func (p *playerMaterial) 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 *playerMaterial) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 20)
	p.fieldMap["id"] = p.ID
	p.fieldMap["playerid"] = p.Playerid
	p.fieldMap["coin"] = p.Coin
	p.fieldMap["diamond"] = p.Diamond
	p.fieldMap["payCount"] = p.PayCount
	p.fieldMap["equipments"] = p.Equipments
	p.fieldMap["fastEquips"] = p.FastEquips
	p.fieldMap["materials"] = p.Materials
	p.fieldMap["roles"] = p.Roles
	p.fieldMap["talents"] = p.Talents
	p.fieldMap["passRoom"] = p.PassRoom
	p.fieldMap["roleRes"] = p.RoleRes
	p.fieldMap["buffMaterials"] = p.BuffMaterials
	p.fieldMap["adLimit"] = p.AdLimit
	p.fieldMap["body"] = p.Body
	p.fieldMap["broadTrigger"] = p.BroadTrigger
	p.fieldMap["treasures"] = p.Treasures
	p.fieldMap["roleCollocate"] = p.RoleCollocate
	p.fieldMap["paySwitch"] = p.PaySwitch
	p.fieldMap["equipHistory"] = p.EquipHistory
}

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

func (p playerMaterial) replaceDB(db *gorm.DB) playerMaterial {
	p.playerMaterialDo.ReplaceDB(db)
	return p
}

type playerMaterialDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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