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

	_playerAttr.playerAttrDo.UseDB(db, opts...)
	_playerAttr.playerAttrDo.UseModel(&model.PlayerAttr{})

	tableName := _playerAttr.playerAttrDo.TableName()
	_playerAttr.ALL = field.NewAsterisk(tableName)
	_playerAttr.ID = field.NewInt64(tableName, "id")
	_playerAttr.Playerid = field.NewInt64(tableName, "playerid")
	_playerAttr.AccID = field.NewInt64(tableName, "accId")
	_playerAttr.ServerID = field.NewInt32(tableName, "serverId")
	_playerAttr.Level = field.NewInt32(tableName, "level")
	_playerAttr.Exp = field.NewInt64(tableName, "exp")
	_playerAttr.Stamina = field.NewInt32(tableName, "stamina")
	_playerAttr.Lastlogintick = field.NewInt64(tableName, "lastlogintick")
	_playerAttr.Lastlogouttick = field.NewInt64(tableName, "lastlogouttick")
	_playerAttr.LastChapter = field.NewString(tableName, "lastChapter")
	_playerAttr.LastStamTick = field.NewInt64(tableName, "lastStamTick")
	_playerAttr.Location = field.NewString(tableName, "location")
	_playerAttr.OpenID = field.NewString(tableName, "openId")
	_playerAttr.NickName = field.NewString(tableName, "nickName")
	_playerAttr.ImgURL = field.NewString(tableName, "imgUrl")
	_playerAttr.Ban = field.NewInt32(tableName, "ban")
	_playerAttr.GdtVid = field.NewString(tableName, "gdtVid")
	_playerAttr.AdID = field.NewString(tableName, "adId")
	_playerAttr.AdSrc = field.NewString(tableName, "adSrc")
	_playerAttr.CreateTime = field.NewTime(tableName, "create_time")
	_playerAttr.CombatEffe = field.NewInt64(tableName, "combatEffe")
	_playerAttr.MaxCombatEffe = field.NewInt64(tableName, "maxCombatEffe")
	_playerAttr.Flag = field.NewInt32(tableName, "flag")

	_playerAttr.fillFieldMap()

	return _playerAttr
}

type playerAttr struct {
	playerAttrDo

	ALL            field.Asterisk
	ID             field.Int64
	Playerid       field.Int64
	AccID          field.Int64
	ServerID       field.Int32
	Level          field.Int32
	Exp            field.Int64
	Stamina        field.Int32
	Lastlogintick  field.Int64
	Lastlogouttick field.Int64
	LastChapter    field.String
	LastStamTick   field.Int64
	Location       field.String
	OpenID         field.String
	NickName       field.String
	ImgURL         field.String
	Ban            field.Int32
	GdtVid         field.String
	AdID           field.String
	AdSrc          field.String
	CreateTime     field.Time
	CombatEffe     field.Int64
	MaxCombatEffe  field.Int64
	Flag           field.Int32

	fieldMap map[string]field.Expr
}

func (p playerAttr) Table(newTableName string) *playerAttr {
	p.playerAttrDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

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

func (p *playerAttr) updateTableName(table string) *playerAttr {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.Playerid = field.NewInt64(table, "playerid")
	p.AccID = field.NewInt64(table, "accId")
	p.ServerID = field.NewInt32(table, "serverId")
	p.Level = field.NewInt32(table, "level")
	p.Exp = field.NewInt64(table, "exp")
	p.Stamina = field.NewInt32(table, "stamina")
	p.Lastlogintick = field.NewInt64(table, "lastlogintick")
	p.Lastlogouttick = field.NewInt64(table, "lastlogouttick")
	p.LastChapter = field.NewString(table, "lastChapter")
	p.LastStamTick = field.NewInt64(table, "lastStamTick")
	p.Location = field.NewString(table, "location")
	p.OpenID = field.NewString(table, "openId")
	p.NickName = field.NewString(table, "nickName")
	p.ImgURL = field.NewString(table, "imgUrl")
	p.Ban = field.NewInt32(table, "ban")
	p.GdtVid = field.NewString(table, "gdtVid")
	p.AdID = field.NewString(table, "adId")
	p.AdSrc = field.NewString(table, "adSrc")
	p.CreateTime = field.NewTime(table, "create_time")
	p.CombatEffe = field.NewInt64(table, "combatEffe")
	p.MaxCombatEffe = field.NewInt64(table, "maxCombatEffe")
	p.Flag = field.NewInt32(table, "flag")

	p.fillFieldMap()

	return p
}

func (p *playerAttr) 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 *playerAttr) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 23)
	p.fieldMap["id"] = p.ID
	p.fieldMap["playerid"] = p.Playerid
	p.fieldMap["accId"] = p.AccID
	p.fieldMap["serverId"] = p.ServerID
	p.fieldMap["level"] = p.Level
	p.fieldMap["exp"] = p.Exp
	p.fieldMap["stamina"] = p.Stamina
	p.fieldMap["lastlogintick"] = p.Lastlogintick
	p.fieldMap["lastlogouttick"] = p.Lastlogouttick
	p.fieldMap["lastChapter"] = p.LastChapter
	p.fieldMap["lastStamTick"] = p.LastStamTick
	p.fieldMap["location"] = p.Location
	p.fieldMap["openId"] = p.OpenID
	p.fieldMap["nickName"] = p.NickName
	p.fieldMap["imgUrl"] = p.ImgURL
	p.fieldMap["ban"] = p.Ban
	p.fieldMap["gdtVid"] = p.GdtVid
	p.fieldMap["adId"] = p.AdID
	p.fieldMap["adSrc"] = p.AdSrc
	p.fieldMap["create_time"] = p.CreateTime
	p.fieldMap["combatEffe"] = p.CombatEffe
	p.fieldMap["maxCombatEffe"] = p.MaxCombatEffe
	p.fieldMap["flag"] = p.Flag
}

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

func (p playerAttr) replaceDB(db *gorm.DB) playerAttr {
	p.playerAttrDo.ReplaceDB(db)
	return p
}

type playerAttrDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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