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

	_gameDataAlarm.gameDataAlarmDo.UseDB(db, opts...)
	_gameDataAlarm.gameDataAlarmDo.UseModel(&model.GameDataAlarm{})

	tableName := _gameDataAlarm.gameDataAlarmDo.TableName()
	_gameDataAlarm.ALL = field.NewAsterisk(tableName)
	_gameDataAlarm.ID = field.NewInt64(tableName, "id")
	_gameDataAlarm.PlayerID = field.NewInt64(tableName, "player_id")
	_gameDataAlarm.Attrs = field.NewString(tableName, "attrs")
	_gameDataAlarm.ServerID = field.NewInt32(tableName, "server_id")
	_gameDataAlarm.Msg = field.NewString(tableName, "msg")
	_gameDataAlarm.Time = field.NewInt64(tableName, "time")
	_gameDataAlarm.Module = field.NewString(tableName, "module")
	_gameDataAlarm.CreatedAt = field.NewTime(tableName, "created_at")

	_gameDataAlarm.fillFieldMap()

	return _gameDataAlarm
}

type gameDataAlarm struct {
	gameDataAlarmDo

	ALL       field.Asterisk
	ID        field.Int64
	PlayerID  field.Int64  // 玩家id
	Attrs     field.String // 错误属性
	ServerID  field.Int32  // 游戏服id
	Msg       field.String // 错误详情
	Time      field.Int64  // 触发时间
	Module    field.String // 触发模块
	CreatedAt field.Time

	fieldMap map[string]field.Expr
}

func (g gameDataAlarm) Table(newTableName string) *gameDataAlarm {
	g.gameDataAlarmDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

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

func (g *gameDataAlarm) updateTableName(table string) *gameDataAlarm {
	g.ALL = field.NewAsterisk(table)
	g.ID = field.NewInt64(table, "id")
	g.PlayerID = field.NewInt64(table, "player_id")
	g.Attrs = field.NewString(table, "attrs")
	g.ServerID = field.NewInt32(table, "server_id")
	g.Msg = field.NewString(table, "msg")
	g.Time = field.NewInt64(table, "time")
	g.Module = field.NewString(table, "module")
	g.CreatedAt = field.NewTime(table, "created_at")

	g.fillFieldMap()

	return g
}

func (g *gameDataAlarm) 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 *gameDataAlarm) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 8)
	g.fieldMap["id"] = g.ID
	g.fieldMap["player_id"] = g.PlayerID
	g.fieldMap["attrs"] = g.Attrs
	g.fieldMap["server_id"] = g.ServerID
	g.fieldMap["msg"] = g.Msg
	g.fieldMap["time"] = g.Time
	g.fieldMap["module"] = g.Module
	g.fieldMap["created_at"] = g.CreatedAt
}

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

func (g gameDataAlarm) replaceDB(db *gorm.DB) gameDataAlarm {
	g.gameDataAlarmDo.ReplaceDB(db)
	return g
}

type gameDataAlarmDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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