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

	_gameAlarmCombatLog.gameAlarmCombatLogDo.UseDB(db, opts...)
	_gameAlarmCombatLog.gameAlarmCombatLogDo.UseModel(&model.GameAlarmCombatLog{})

	tableName := _gameAlarmCombatLog.gameAlarmCombatLogDo.TableName()
	_gameAlarmCombatLog.ALL = field.NewAsterisk(tableName)
	_gameAlarmCombatLog.ID = field.NewInt64(tableName, "id")
	_gameAlarmCombatLog.OriginID = field.NewInt64(tableName, "origin_id")
	_gameAlarmCombatLog.OriginTime = field.NewString(tableName, "origin_time")
	_gameAlarmCombatLog.YearMonth = field.NewString(tableName, "year_month")
	_gameAlarmCombatLog.PlayerID = field.NewInt64(tableName, "player_id")
	_gameAlarmCombatLog.ServerID = field.NewInt32(tableName, "server_id")
	_gameAlarmCombatLog.Dps = field.NewFloat64(tableName, "dps")
	_gameAlarmCombatLog.Rate = field.NewFloat64(tableName, "rate")
	_gameAlarmCombatLog.Valuation = field.NewFloat64(tableName, "valuation")
	_gameAlarmCombatLog.Damage = field.NewFloat64(tableName, "damage")
	_gameAlarmCombatLog.Ratio = field.NewFloat64(tableName, "ratio")
	_gameAlarmCombatLog.AlarmData = field.NewString(tableName, "alarm_data")
	_gameAlarmCombatLog.RoleInfo = field.NewString(tableName, "role_info")
	_gameAlarmCombatLog.CreatedAt = field.NewTime(tableName, "created_at")

	_gameAlarmCombatLog.fillFieldMap()

	return _gameAlarmCombatLog
}

type gameAlarmCombatLog struct {
	gameAlarmCombatLogDo

	ALL        field.Asterisk
	ID         field.Int64
	OriginID   field.Int64 // 战斗信息表id
	OriginTime field.String
	YearMonth  field.String // 年月
	PlayerID   field.Int64  // 玩家id
	ServerID   field.Int32  // 游戏服id
	Dps        field.Float64
	Rate       field.Float64 // 技能倍率
	Valuation  field.Float64 // 估值伤害
	Damage     field.Float64 // 实际伤害
	Ratio      field.Float64 // 实际伤害值/估值
	AlarmData  field.String  // 异常数据
	RoleInfo   field.String  // 角色信息
	CreatedAt  field.Time

	fieldMap map[string]field.Expr
}

func (g gameAlarmCombatLog) Table(newTableName string) *gameAlarmCombatLog {
	g.gameAlarmCombatLogDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

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

func (g *gameAlarmCombatLog) updateTableName(table string) *gameAlarmCombatLog {
	g.ALL = field.NewAsterisk(table)
	g.ID = field.NewInt64(table, "id")
	g.OriginID = field.NewInt64(table, "origin_id")
	g.OriginTime = field.NewString(table, "origin_time")
	g.YearMonth = field.NewString(table, "year_month")
	g.PlayerID = field.NewInt64(table, "player_id")
	g.ServerID = field.NewInt32(table, "server_id")
	g.Dps = field.NewFloat64(table, "dps")
	g.Rate = field.NewFloat64(table, "rate")
	g.Valuation = field.NewFloat64(table, "valuation")
	g.Damage = field.NewFloat64(table, "damage")
	g.Ratio = field.NewFloat64(table, "ratio")
	g.AlarmData = field.NewString(table, "alarm_data")
	g.RoleInfo = field.NewString(table, "role_info")
	g.CreatedAt = field.NewTime(table, "created_at")

	g.fillFieldMap()

	return g
}

func (g *gameAlarmCombatLog) 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 *gameAlarmCombatLog) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 14)
	g.fieldMap["id"] = g.ID
	g.fieldMap["origin_id"] = g.OriginID
	g.fieldMap["origin_time"] = g.OriginTime
	g.fieldMap["year_month"] = g.YearMonth
	g.fieldMap["player_id"] = g.PlayerID
	g.fieldMap["server_id"] = g.ServerID
	g.fieldMap["dps"] = g.Dps
	g.fieldMap["rate"] = g.Rate
	g.fieldMap["valuation"] = g.Valuation
	g.fieldMap["damage"] = g.Damage
	g.fieldMap["ratio"] = g.Ratio
	g.fieldMap["alarm_data"] = g.AlarmData
	g.fieldMap["role_info"] = g.RoleInfo
	g.fieldMap["created_at"] = g.CreatedAt
}

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

func (g gameAlarmCombatLog) replaceDB(db *gorm.DB) gameAlarmCombatLog {
	g.gameAlarmCombatLogDo.ReplaceDB(db)
	return g
}

type gameAlarmCombatLogDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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