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

	_climbfloor.climbfloorDo.UseDB(db, opts...)
	_climbfloor.climbfloorDo.UseModel(&model.Climbfloor{})

	tableName := _climbfloor.climbfloorDo.TableName()
	_climbfloor.ALL = field.NewAsterisk(tableName)
	_climbfloor.Playerid = field.NewInt64(tableName, "playerid")
	_climbfloor.MaxFloor = field.NewInt32(tableName, "maxFloor")
	_climbfloor.Floors = field.NewString(tableName, "floors")
	_climbfloor.DayBuy = field.NewString(tableName, "dayBuy")
	_climbfloor.VipBuff = field.NewString(tableName, "vipBuff")

	_climbfloor.fillFieldMap()

	return _climbfloor
}

type climbfloor struct {
	climbfloorDo

	ALL      field.Asterisk
	Playerid field.Int64
	MaxFloor field.Int32
	Floors   field.String
	DayBuy   field.String
	VipBuff  field.String

	fieldMap map[string]field.Expr
}

func (c climbfloor) Table(newTableName string) *climbfloor {
	c.climbfloorDo.UseTable(newTableName)
	return c.updateTableName(newTableName)
}

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

func (c *climbfloor) updateTableName(table string) *climbfloor {
	c.ALL = field.NewAsterisk(table)
	c.Playerid = field.NewInt64(table, "playerid")
	c.MaxFloor = field.NewInt32(table, "maxFloor")
	c.Floors = field.NewString(table, "floors")
	c.DayBuy = field.NewString(table, "dayBuy")
	c.VipBuff = field.NewString(table, "vipBuff")

	c.fillFieldMap()

	return c
}

func (c *climbfloor) 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 *climbfloor) fillFieldMap() {
	c.fieldMap = make(map[string]field.Expr, 5)
	c.fieldMap["playerid"] = c.Playerid
	c.fieldMap["maxFloor"] = c.MaxFloor
	c.fieldMap["floors"] = c.Floors
	c.fieldMap["dayBuy"] = c.DayBuy
	c.fieldMap["vipBuff"] = c.VipBuff
}

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

func (c climbfloor) replaceDB(db *gorm.DB) climbfloor {
	c.climbfloorDo.ReplaceDB(db)
	return c
}

type climbfloorDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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