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

	_changedPlayer.changedPlayerDo.UseDB(db, opts...)
	_changedPlayer.changedPlayerDo.UseModel(&model.ChangedPlayer{})

	tableName := _changedPlayer.changedPlayerDo.TableName()
	_changedPlayer.ALL = field.NewAsterisk(tableName)
	_changedPlayer.ID = field.NewInt64(tableName, "id")
	_changedPlayer.Playerid = field.NewInt64(tableName, "playerid")
	_changedPlayer.ServerID = field.NewInt32(tableName, "server_id")
	_changedPlayer.ExpendCoin = field.NewInt64(tableName, "expend_coin")
	_changedPlayer.ExpendDiamond = field.NewInt64(tableName, "expend_diamond")
	_changedPlayer.LastCid = field.NewInt64(tableName, "last_cid")
	_changedPlayer.CreatedAt = field.NewTime(tableName, "created_at")
	_changedPlayer.UpdatedAt = field.NewTime(tableName, "updated_at")

	_changedPlayer.fillFieldMap()

	return _changedPlayer
}

type changedPlayer struct {
	changedPlayerDo

	ALL           field.Asterisk
	ID            field.Int64
	Playerid      field.Int64 // 玩家ID
	ServerID      field.Int32 // 服务器ID
	ExpendCoin    field.Int64 // 消耗金币
	ExpendDiamond field.Int64 // 消耗钻石
	LastCid       field.Int64 // 最后同步的消费ID
	CreatedAt     field.Time  // 创建时间
	UpdatedAt     field.Time  // 更新日期

	fieldMap map[string]field.Expr
}

func (c changedPlayer) Table(newTableName string) *changedPlayer {
	c.changedPlayerDo.UseTable(newTableName)
	return c.updateTableName(newTableName)
}

func (c changedPlayer) As(alias string) *changedPlayer {
	c.changedPlayerDo.DO = *(c.changedPlayerDo.As(alias).(*gen.DO))
	return c.updateTableName(alias)
}

func (c *changedPlayer) updateTableName(table string) *changedPlayer {
	c.ALL = field.NewAsterisk(table)
	c.ID = field.NewInt64(table, "id")
	c.Playerid = field.NewInt64(table, "playerid")
	c.ServerID = field.NewInt32(table, "server_id")
	c.ExpendCoin = field.NewInt64(table, "expend_coin")
	c.ExpendDiamond = field.NewInt64(table, "expend_diamond")
	c.LastCid = field.NewInt64(table, "last_cid")
	c.CreatedAt = field.NewTime(table, "created_at")
	c.UpdatedAt = field.NewTime(table, "updated_at")

	c.fillFieldMap()

	return c
}

func (c *changedPlayer) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
	_f, ok := c.fieldMap[fieldName]
	if !ok || _f == nil {
		return nil, false
	}
	_oe, ok := _f.(field.OrderExpr)
	return _oe, ok
}

func (c *changedPlayer) fillFieldMap() {
	c.fieldMap = make(map[string]field.Expr, 8)
	c.fieldMap["id"] = c.ID
	c.fieldMap["playerid"] = c.Playerid
	c.fieldMap["server_id"] = c.ServerID
	c.fieldMap["expend_coin"] = c.ExpendCoin
	c.fieldMap["expend_diamond"] = c.ExpendDiamond
	c.fieldMap["last_cid"] = c.LastCid
	c.fieldMap["created_at"] = c.CreatedAt
	c.fieldMap["updated_at"] = c.UpdatedAt
}

func (c changedPlayer) clone(db *gorm.DB) changedPlayer {
	c.changedPlayerDo.ReplaceConnPool(db.Statement.ConnPool)
	return c
}

func (c changedPlayer) replaceDB(db *gorm.DB) changedPlayer {
	c.changedPlayerDo.ReplaceDB(db)
	return c
}

type changedPlayerDo struct{ gen.DO }

func (c changedPlayerDo) Debug() *changedPlayerDo {
	return c.withDO(c.DO.Debug())
}

func (c changedPlayerDo) WithContext(ctx context.Context) *changedPlayerDo {
	return c.withDO(c.DO.WithContext(ctx))
}

func (c changedPlayerDo) ReadDB() *changedPlayerDo {
	return c.Clauses(dbresolver.Read)
}

func (c changedPlayerDo) WriteDB() *changedPlayerDo {
	return c.Clauses(dbresolver.Write)
}

func (c changedPlayerDo) Session(config *gorm.Session) *changedPlayerDo {
	return c.withDO(c.DO.Session(config))
}

func (c changedPlayerDo) Clauses(conds ...clause.Expression) *changedPlayerDo {
	return c.withDO(c.DO.Clauses(conds...))
}

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

func (c changedPlayerDo) Not(conds ...gen.Condition) *changedPlayerDo {
	return c.withDO(c.DO.Not(conds...))
}

func (c changedPlayerDo) Or(conds ...gen.Condition) *changedPlayerDo {
	return c.withDO(c.DO.Or(conds...))
}

func (c changedPlayerDo) Select(conds ...field.Expr) *changedPlayerDo {
	return c.withDO(c.DO.Select(conds...))
}

func (c changedPlayerDo) Where(conds ...gen.Condition) *changedPlayerDo {
	return c.withDO(c.DO.Where(conds...))
}

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

func (c changedPlayerDo) Order(conds ...field.Expr) *changedPlayerDo {
	return c.withDO(c.DO.Order(conds...))
}

func (c changedPlayerDo) Distinct(cols ...field.Expr) *changedPlayerDo {
	return c.withDO(c.DO.Distinct(cols...))
}

func (c changedPlayerDo) Omit(cols ...field.Expr) *changedPlayerDo {
	return c.withDO(c.DO.Omit(cols...))
}

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

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

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

func (c changedPlayerDo) Group(cols ...field.Expr) *changedPlayerDo {
	return c.withDO(c.DO.Group(cols...))
}

func (c changedPlayerDo) Having(conds ...gen.Condition) *changedPlayerDo {
	return c.withDO(c.DO.Having(conds...))
}

func (c changedPlayerDo) Limit(limit int) *changedPlayerDo {
	return c.withDO(c.DO.Limit(limit))
}

func (c changedPlayerDo) Offset(offset int) *changedPlayerDo {
	return c.withDO(c.DO.Offset(offset))
}

func (c changedPlayerDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *changedPlayerDo {
	return c.withDO(c.DO.Scopes(funcs...))
}

func (c changedPlayerDo) Unscoped() *changedPlayerDo {
	return c.withDO(c.DO.Unscoped())
}

func (c changedPlayerDo) Create(values ...*model.ChangedPlayer) error {
	if len(values) == 0 {
		return nil
	}
	return c.DO.Create(values)
}

func (c changedPlayerDo) CreateInBatches(values []*model.ChangedPlayer, batchSize int) error {
	return c.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 (c changedPlayerDo) Save(values ...*model.ChangedPlayer) error {
	if len(values) == 0 {
		return nil
	}
	return c.DO.Save(values)
}

func (c changedPlayerDo) First() (*model.ChangedPlayer, error) {
	if result, err := c.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChangedPlayer), nil
	}
}

func (c changedPlayerDo) Take() (*model.ChangedPlayer, error) {
	if result, err := c.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChangedPlayer), nil
	}
}

func (c changedPlayerDo) Last() (*model.ChangedPlayer, error) {
	if result, err := c.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChangedPlayer), nil
	}
}

func (c changedPlayerDo) Find() ([]*model.ChangedPlayer, error) {
	result, err := c.DO.Find()
	return result.([]*model.ChangedPlayer), err
}

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

func (c changedPlayerDo) Attrs(attrs ...field.AssignExpr) *changedPlayerDo {
	return c.withDO(c.DO.Attrs(attrs...))
}

func (c changedPlayerDo) Assign(attrs ...field.AssignExpr) *changedPlayerDo {
	return c.withDO(c.DO.Assign(attrs...))
}

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

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

func (c changedPlayerDo) FirstOrInit() (*model.ChangedPlayer, error) {
	if result, err := c.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChangedPlayer), nil
	}
}

func (c changedPlayerDo) FirstOrCreate() (*model.ChangedPlayer, error) {
	if result, err := c.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ChangedPlayer), nil
	}
}

func (c changedPlayerDo) FindByPage(offset int, limit int) (result []*model.ChangedPlayer, count int64, err error) {
	result, err = c.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 = c.Offset(-1).Limit(-1).Count()
	return
}

func (c changedPlayerDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
	count, err = c.Count()
	if err != nil {
		return
	}

	err = c.Offset(offset).Limit(limit).Scan(result)
	return
}

func (c changedPlayerDo) Scan(result interface{}) (err error) {
	return c.DO.Scan(result)
}

func (c changedPlayerDo) Delete(models ...*model.ChangedPlayer) (result gen.ResultInfo, err error) {
	return c.DO.Delete(models)
}

func (c *changedPlayerDo) withDO(do gen.Dao) *changedPlayerDo {
	c.DO = *do.(*gen.DO)
	return c
}
