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

	_gemPlayer.gemPlayerDo.UseDB(db, opts...)
	_gemPlayer.gemPlayerDo.UseModel(&model.GemPlayer{})

	tableName := _gemPlayer.gemPlayerDo.TableName()
	_gemPlayer.ALL = field.NewAsterisk(tableName)
	_gemPlayer.ID = field.NewInt64(tableName, "id")
	_gemPlayer.UserID = field.NewInt64(tableName, "user_id")
	_gemPlayer.ServerID = field.NewInt32(tableName, "server_id")
	_gemPlayer.Part = field.NewInt64(tableName, "part")
	_gemPlayer.SlotNum = field.NewInt64(tableName, "slot_num")
	_gemPlayer.Lv1 = field.NewInt64(tableName, "lv1")
	_gemPlayer.Lv2 = field.NewInt64(tableName, "lv2")
	_gemPlayer.Lv3 = field.NewInt64(tableName, "lv3")
	_gemPlayer.Lv4 = field.NewInt64(tableName, "lv4")
	_gemPlayer.Lv5 = field.NewInt64(tableName, "lv5")
	_gemPlayer.Lv6 = field.NewInt64(tableName, "lv6")
	_gemPlayer.UpdatedAt = field.NewTime(tableName, "updated_at")

	_gemPlayer.fillFieldMap()

	return _gemPlayer
}

type gemPlayer struct {
	gemPlayerDo

	ALL       field.Asterisk
	ID        field.Int64
	UserID    field.Int64 // 玩家ID
	ServerID  field.Int32 // 服务器ID
	Part      field.Int64 // 部位（宝石）类型
	SlotNum   field.Int64 // 槽位数量
	Lv1       field.Int64 // 宝石1级镶嵌数量
	Lv2       field.Int64 // 宝石2级镶嵌数量
	Lv3       field.Int64 // 宝石3级镶嵌数量
	Lv4       field.Int64 // 宝石4级镶嵌数量
	Lv5       field.Int64 // 宝石5级镶嵌数量
	Lv6       field.Int64 // 宝石6级镶嵌数量
	UpdatedAt field.Time  // 更新时间

	fieldMap map[string]field.Expr
}

func (g gemPlayer) Table(newTableName string) *gemPlayer {
	g.gemPlayerDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

func (g gemPlayer) As(alias string) *gemPlayer {
	g.gemPlayerDo.DO = *(g.gemPlayerDo.As(alias).(*gen.DO))
	return g.updateTableName(alias)
}

func (g *gemPlayer) updateTableName(table string) *gemPlayer {
	g.ALL = field.NewAsterisk(table)
	g.ID = field.NewInt64(table, "id")
	g.UserID = field.NewInt64(table, "user_id")
	g.ServerID = field.NewInt32(table, "server_id")
	g.Part = field.NewInt64(table, "part")
	g.SlotNum = field.NewInt64(table, "slot_num")
	g.Lv1 = field.NewInt64(table, "lv1")
	g.Lv2 = field.NewInt64(table, "lv2")
	g.Lv3 = field.NewInt64(table, "lv3")
	g.Lv4 = field.NewInt64(table, "lv4")
	g.Lv5 = field.NewInt64(table, "lv5")
	g.Lv6 = field.NewInt64(table, "lv6")
	g.UpdatedAt = field.NewTime(table, "updated_at")

	g.fillFieldMap()

	return g
}

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

func (g *gemPlayer) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 12)
	g.fieldMap["id"] = g.ID
	g.fieldMap["user_id"] = g.UserID
	g.fieldMap["server_id"] = g.ServerID
	g.fieldMap["part"] = g.Part
	g.fieldMap["slot_num"] = g.SlotNum
	g.fieldMap["lv1"] = g.Lv1
	g.fieldMap["lv2"] = g.Lv2
	g.fieldMap["lv3"] = g.Lv3
	g.fieldMap["lv4"] = g.Lv4
	g.fieldMap["lv5"] = g.Lv5
	g.fieldMap["lv6"] = g.Lv6
	g.fieldMap["updated_at"] = g.UpdatedAt
}

func (g gemPlayer) clone(db *gorm.DB) gemPlayer {
	g.gemPlayerDo.ReplaceConnPool(db.Statement.ConnPool)
	return g
}

func (g gemPlayer) replaceDB(db *gorm.DB) gemPlayer {
	g.gemPlayerDo.ReplaceDB(db)
	return g
}

type gemPlayerDo struct{ gen.DO }

func (g gemPlayerDo) Debug() *gemPlayerDo {
	return g.withDO(g.DO.Debug())
}

func (g gemPlayerDo) WithContext(ctx context.Context) *gemPlayerDo {
	return g.withDO(g.DO.WithContext(ctx))
}

func (g gemPlayerDo) ReadDB() *gemPlayerDo {
	return g.Clauses(dbresolver.Read)
}

func (g gemPlayerDo) WriteDB() *gemPlayerDo {
	return g.Clauses(dbresolver.Write)
}

func (g gemPlayerDo) Session(config *gorm.Session) *gemPlayerDo {
	return g.withDO(g.DO.Session(config))
}

func (g gemPlayerDo) Clauses(conds ...clause.Expression) *gemPlayerDo {
	return g.withDO(g.DO.Clauses(conds...))
}

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

func (g gemPlayerDo) Not(conds ...gen.Condition) *gemPlayerDo {
	return g.withDO(g.DO.Not(conds...))
}

func (g gemPlayerDo) Or(conds ...gen.Condition) *gemPlayerDo {
	return g.withDO(g.DO.Or(conds...))
}

func (g gemPlayerDo) Select(conds ...field.Expr) *gemPlayerDo {
	return g.withDO(g.DO.Select(conds...))
}

func (g gemPlayerDo) Where(conds ...gen.Condition) *gemPlayerDo {
	return g.withDO(g.DO.Where(conds...))
}

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

func (g gemPlayerDo) Order(conds ...field.Expr) *gemPlayerDo {
	return g.withDO(g.DO.Order(conds...))
}

func (g gemPlayerDo) Distinct(cols ...field.Expr) *gemPlayerDo {
	return g.withDO(g.DO.Distinct(cols...))
}

func (g gemPlayerDo) Omit(cols ...field.Expr) *gemPlayerDo {
	return g.withDO(g.DO.Omit(cols...))
}

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

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

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

func (g gemPlayerDo) Group(cols ...field.Expr) *gemPlayerDo {
	return g.withDO(g.DO.Group(cols...))
}

func (g gemPlayerDo) Having(conds ...gen.Condition) *gemPlayerDo {
	return g.withDO(g.DO.Having(conds...))
}

func (g gemPlayerDo) Limit(limit int) *gemPlayerDo {
	return g.withDO(g.DO.Limit(limit))
}

func (g gemPlayerDo) Offset(offset int) *gemPlayerDo {
	return g.withDO(g.DO.Offset(offset))
}

func (g gemPlayerDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *gemPlayerDo {
	return g.withDO(g.DO.Scopes(funcs...))
}

func (g gemPlayerDo) Unscoped() *gemPlayerDo {
	return g.withDO(g.DO.Unscoped())
}

func (g gemPlayerDo) Create(values ...*model.GemPlayer) error {
	if len(values) == 0 {
		return nil
	}
	return g.DO.Create(values)
}

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

func (g gemPlayerDo) First() (*model.GemPlayer, error) {
	if result, err := g.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.GemPlayer), nil
	}
}

func (g gemPlayerDo) Take() (*model.GemPlayer, error) {
	if result, err := g.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.GemPlayer), nil
	}
}

func (g gemPlayerDo) Last() (*model.GemPlayer, error) {
	if result, err := g.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.GemPlayer), nil
	}
}

func (g gemPlayerDo) Find() ([]*model.GemPlayer, error) {
	result, err := g.DO.Find()
	return result.([]*model.GemPlayer), err
}

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

func (g gemPlayerDo) Attrs(attrs ...field.AssignExpr) *gemPlayerDo {
	return g.withDO(g.DO.Attrs(attrs...))
}

func (g gemPlayerDo) Assign(attrs ...field.AssignExpr) *gemPlayerDo {
	return g.withDO(g.DO.Assign(attrs...))
}

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

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

func (g gemPlayerDo) FirstOrInit() (*model.GemPlayer, error) {
	if result, err := g.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.GemPlayer), nil
	}
}

func (g gemPlayerDo) FirstOrCreate() (*model.GemPlayer, error) {
	if result, err := g.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.GemPlayer), nil
	}
}

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

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

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

func (g gemPlayerDo) Scan(result interface{}) (err error) {
	return g.DO.Scan(result)
}

func (g gemPlayerDo) Delete(models ...*model.GemPlayer) (result gen.ResultInfo, err error) {
	return g.DO.Delete(models)
}

func (g *gemPlayerDo) withDO(do gen.Dao) *gemPlayerDo {
	g.DO = *do.(*gen.DO)
	return g
}
