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

	_bosswar.bosswarDo.UseDB(db, opts...)
	_bosswar.bosswarDo.UseModel(&model.Bosswar{})

	tableName := _bosswar.bosswarDo.TableName()
	_bosswar.ALL = field.NewAsterisk(tableName)
	_bosswar.ID = field.NewInt64(tableName, "id")
	_bosswar.GroupID = field.NewInt32(tableName, "groupId")
	_bosswar.AllBoss = field.NewString(tableName, "allBoss")
	_bosswar.Fighting = field.NewInt32(tableName, "fighting")
	_bosswar.HpUp = field.NewInt64(tableName, "hpUp")
	_bosswar.AtkUp = field.NewInt32(tableName, "atkUp")
	_bosswar.YearDay = field.NewInt32(tableName, "yearDay")
	_bosswar.StartTime = field.NewTime(tableName, "startTime")
	_bosswar.EndTime = field.NewTime(tableName, "endTime")
	_bosswar.EleAtkUp = field.NewInt32(tableName, "ele_atk_up")
	_bosswar.GoldEleDefUp = field.NewInt32(tableName, "gold_ele_def_up")
	_bosswar.WoodEleDefUp = field.NewInt32(tableName, "wood_ele_def_up")
	_bosswar.WaterEleDefUp = field.NewInt32(tableName, "water_ele_def_up")
	_bosswar.FireEleDefUp = field.NewInt32(tableName, "fire_ele_def_up")
	_bosswar.SoilEleDefUp = field.NewInt32(tableName, "soil_ele_def_up")
	_bosswar.EleIncLevel = field.NewInt32(tableName, "ele_inc_level")

	_bosswar.fillFieldMap()

	return _bosswar
}

type bosswar struct {
	bosswarDo

	ALL           field.Asterisk
	ID            field.Int64
	GroupID       field.Int32
	AllBoss       field.String
	Fighting      field.Int32
	HpUp          field.Int64
	AtkUp         field.Int32
	YearDay       field.Int32
	StartTime     field.Time
	EndTime       field.Time
	EleAtkUp      field.Int32
	GoldEleDefUp  field.Int32
	WoodEleDefUp  field.Int32
	WaterEleDefUp field.Int32
	FireEleDefUp  field.Int32
	SoilEleDefUp  field.Int32
	EleIncLevel   field.Int32

	fieldMap map[string]field.Expr
}

func (b bosswar) Table(newTableName string) *bosswar {
	b.bosswarDo.UseTable(newTableName)
	return b.updateTableName(newTableName)
}

func (b bosswar) As(alias string) *bosswar {
	b.bosswarDo.DO = *(b.bosswarDo.As(alias).(*gen.DO))
	return b.updateTableName(alias)
}

func (b *bosswar) updateTableName(table string) *bosswar {
	b.ALL = field.NewAsterisk(table)
	b.ID = field.NewInt64(table, "id")
	b.GroupID = field.NewInt32(table, "groupId")
	b.AllBoss = field.NewString(table, "allBoss")
	b.Fighting = field.NewInt32(table, "fighting")
	b.HpUp = field.NewInt64(table, "hpUp")
	b.AtkUp = field.NewInt32(table, "atkUp")
	b.YearDay = field.NewInt32(table, "yearDay")
	b.StartTime = field.NewTime(table, "startTime")
	b.EndTime = field.NewTime(table, "endTime")
	b.EleAtkUp = field.NewInt32(table, "ele_atk_up")
	b.GoldEleDefUp = field.NewInt32(table, "gold_ele_def_up")
	b.WoodEleDefUp = field.NewInt32(table, "wood_ele_def_up")
	b.WaterEleDefUp = field.NewInt32(table, "water_ele_def_up")
	b.FireEleDefUp = field.NewInt32(table, "fire_ele_def_up")
	b.SoilEleDefUp = field.NewInt32(table, "soil_ele_def_up")
	b.EleIncLevel = field.NewInt32(table, "ele_inc_level")

	b.fillFieldMap()

	return b
}

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

func (b *bosswar) fillFieldMap() {
	b.fieldMap = make(map[string]field.Expr, 16)
	b.fieldMap["id"] = b.ID
	b.fieldMap["groupId"] = b.GroupID
	b.fieldMap["allBoss"] = b.AllBoss
	b.fieldMap["fighting"] = b.Fighting
	b.fieldMap["hpUp"] = b.HpUp
	b.fieldMap["atkUp"] = b.AtkUp
	b.fieldMap["yearDay"] = b.YearDay
	b.fieldMap["startTime"] = b.StartTime
	b.fieldMap["endTime"] = b.EndTime
	b.fieldMap["ele_atk_up"] = b.EleAtkUp
	b.fieldMap["gold_ele_def_up"] = b.GoldEleDefUp
	b.fieldMap["wood_ele_def_up"] = b.WoodEleDefUp
	b.fieldMap["water_ele_def_up"] = b.WaterEleDefUp
	b.fieldMap["fire_ele_def_up"] = b.FireEleDefUp
	b.fieldMap["soil_ele_def_up"] = b.SoilEleDefUp
	b.fieldMap["ele_inc_level"] = b.EleIncLevel
}

func (b bosswar) clone(db *gorm.DB) bosswar {
	b.bosswarDo.ReplaceConnPool(db.Statement.ConnPool)
	return b
}

func (b bosswar) replaceDB(db *gorm.DB) bosswar {
	b.bosswarDo.ReplaceDB(db)
	return b
}

type bosswarDo struct{ gen.DO }

func (b bosswarDo) Debug() *bosswarDo {
	return b.withDO(b.DO.Debug())
}

func (b bosswarDo) WithContext(ctx context.Context) *bosswarDo {
	return b.withDO(b.DO.WithContext(ctx))
}

func (b bosswarDo) ReadDB() *bosswarDo {
	return b.Clauses(dbresolver.Read)
}

func (b bosswarDo) WriteDB() *bosswarDo {
	return b.Clauses(dbresolver.Write)
}

func (b bosswarDo) Session(config *gorm.Session) *bosswarDo {
	return b.withDO(b.DO.Session(config))
}

func (b bosswarDo) Clauses(conds ...clause.Expression) *bosswarDo {
	return b.withDO(b.DO.Clauses(conds...))
}

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

func (b bosswarDo) Not(conds ...gen.Condition) *bosswarDo {
	return b.withDO(b.DO.Not(conds...))
}

func (b bosswarDo) Or(conds ...gen.Condition) *bosswarDo {
	return b.withDO(b.DO.Or(conds...))
}

func (b bosswarDo) Select(conds ...field.Expr) *bosswarDo {
	return b.withDO(b.DO.Select(conds...))
}

func (b bosswarDo) Where(conds ...gen.Condition) *bosswarDo {
	return b.withDO(b.DO.Where(conds...))
}

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

func (b bosswarDo) Order(conds ...field.Expr) *bosswarDo {
	return b.withDO(b.DO.Order(conds...))
}

func (b bosswarDo) Distinct(cols ...field.Expr) *bosswarDo {
	return b.withDO(b.DO.Distinct(cols...))
}

func (b bosswarDo) Omit(cols ...field.Expr) *bosswarDo {
	return b.withDO(b.DO.Omit(cols...))
}

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

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

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

func (b bosswarDo) Group(cols ...field.Expr) *bosswarDo {
	return b.withDO(b.DO.Group(cols...))
}

func (b bosswarDo) Having(conds ...gen.Condition) *bosswarDo {
	return b.withDO(b.DO.Having(conds...))
}

func (b bosswarDo) Limit(limit int) *bosswarDo {
	return b.withDO(b.DO.Limit(limit))
}

func (b bosswarDo) Offset(offset int) *bosswarDo {
	return b.withDO(b.DO.Offset(offset))
}

func (b bosswarDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *bosswarDo {
	return b.withDO(b.DO.Scopes(funcs...))
}

func (b bosswarDo) Unscoped() *bosswarDo {
	return b.withDO(b.DO.Unscoped())
}

func (b bosswarDo) Create(values ...*model.Bosswar) error {
	if len(values) == 0 {
		return nil
	}
	return b.DO.Create(values)
}

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

func (b bosswarDo) First() (*model.Bosswar, error) {
	if result, err := b.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.Bosswar), nil
	}
}

func (b bosswarDo) Take() (*model.Bosswar, error) {
	if result, err := b.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.Bosswar), nil
	}
}

func (b bosswarDo) Last() (*model.Bosswar, error) {
	if result, err := b.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.Bosswar), nil
	}
}

func (b bosswarDo) Find() ([]*model.Bosswar, error) {
	result, err := b.DO.Find()
	return result.([]*model.Bosswar), err
}

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

func (b bosswarDo) Attrs(attrs ...field.AssignExpr) *bosswarDo {
	return b.withDO(b.DO.Attrs(attrs...))
}

func (b bosswarDo) Assign(attrs ...field.AssignExpr) *bosswarDo {
	return b.withDO(b.DO.Assign(attrs...))
}

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

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

func (b bosswarDo) FirstOrInit() (*model.Bosswar, error) {
	if result, err := b.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.Bosswar), nil
	}
}

func (b bosswarDo) FirstOrCreate() (*model.Bosswar, error) {
	if result, err := b.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.Bosswar), nil
	}
}

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

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

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

func (b bosswarDo) Scan(result interface{}) (err error) {
	return b.DO.Scan(result)
}

func (b bosswarDo) Delete(models ...*model.Bosswar) (result gen.ResultInfo, err error) {
	return b.DO.Delete(models)
}

func (b *bosswarDo) withDO(do gen.Dao) *bosswarDo {
	b.DO = *do.(*gen.DO)
	return b
}
