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

	_gemStat.gemStatDo.UseDB(db, opts...)
	_gemStat.gemStatDo.UseModel(&model.GemStat{})

	tableName := _gemStat.gemStatDo.TableName()
	_gemStat.ALL = field.NewAsterisk(tableName)
	_gemStat.ID = field.NewInt64(tableName, "id")
	_gemStat.ServerID = field.NewInt32(tableName, "server_id")
	_gemStat.Part = field.NewInt64(tableName, "part")
	_gemStat.Slot1 = field.NewInt64(tableName, "slot1")
	_gemStat.Slot2 = field.NewInt64(tableName, "slot2")
	_gemStat.Slot3 = field.NewInt64(tableName, "slot3")
	_gemStat.Slot4 = field.NewInt64(tableName, "slot4")
	_gemStat.Lv1 = field.NewInt64(tableName, "lv1")
	_gemStat.Lv2 = field.NewInt64(tableName, "lv2")
	_gemStat.Lv3 = field.NewInt64(tableName, "lv3")
	_gemStat.Lv4 = field.NewInt64(tableName, "lv4")
	_gemStat.Lv5 = field.NewInt64(tableName, "lv5")
	_gemStat.Lv6 = field.NewInt64(tableName, "lv6")
	_gemStat.Date = field.NewString(tableName, "date")

	_gemStat.fillFieldMap()

	return _gemStat
}

type gemStat struct {
	gemStatDo

	ALL      field.Asterisk
	ID       field.Int64
	ServerID field.Int32  // 服务器ID
	Part     field.Int64  // 部位（宝石）类型
	Slot1    field.Int64  // 宝石位1
	Slot2    field.Int64  // 宝石位2
	Slot3    field.Int64  // 宝石位3
	Slot4    field.Int64  // 宝石位4
	Lv1      field.Int64  // 宝石1级
	Lv2      field.Int64  // 宝石2级
	Lv3      field.Int64  // 宝石3级
	Lv4      field.Int64  // 宝石4级
	Lv5      field.Int64  // 宝石5级
	Lv6      field.Int64  // 宝石6级
	Date     field.String // 触发日期 2005-01-02

	fieldMap map[string]field.Expr
}

func (g gemStat) Table(newTableName string) *gemStat {
	g.gemStatDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

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

func (g *gemStat) updateTableName(table string) *gemStat {
	g.ALL = field.NewAsterisk(table)
	g.ID = field.NewInt64(table, "id")
	g.ServerID = field.NewInt32(table, "server_id")
	g.Part = field.NewInt64(table, "part")
	g.Slot1 = field.NewInt64(table, "slot1")
	g.Slot2 = field.NewInt64(table, "slot2")
	g.Slot3 = field.NewInt64(table, "slot3")
	g.Slot4 = field.NewInt64(table, "slot4")
	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.Date = field.NewString(table, "date")

	g.fillFieldMap()

	return g
}

func (g *gemStat) 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 *gemStat) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 14)
	g.fieldMap["id"] = g.ID
	g.fieldMap["server_id"] = g.ServerID
	g.fieldMap["part"] = g.Part
	g.fieldMap["slot1"] = g.Slot1
	g.fieldMap["slot2"] = g.Slot2
	g.fieldMap["slot3"] = g.Slot3
	g.fieldMap["slot4"] = g.Slot4
	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["date"] = g.Date
}

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

func (g gemStat) replaceDB(db *gorm.DB) gemStat {
	g.gemStatDo.ReplaceDB(db)
	return g
}

type gemStatDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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