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

	_grandmasterLog.grandmasterLogDo.UseDB(db, opts...)
	_grandmasterLog.grandmasterLogDo.UseModel(&model.GrandmasterLog{})

	tableName := _grandmasterLog.grandmasterLogDo.TableName()
	_grandmasterLog.ALL = field.NewAsterisk(tableName)
	_grandmasterLog.ID = field.NewInt64(tableName, "id")
	_grandmasterLog.UserID = field.NewInt64(tableName, "user_id")
	_grandmasterLog.ServerID = field.NewInt32(tableName, "server_id")
	_grandmasterLog.ChannelID = field.NewString(tableName, "channel_id")
	_grandmasterLog.EventID = field.NewInt32(tableName, "event_id")
	_grandmasterLog.MatchSeconds = field.NewInt64(tableName, "match_seconds")
	_grandmasterLog.DanScore = field.NewInt64(tableName, "dan_score")
	_grandmasterLog.BattleWaves = field.NewInt64(tableName, "battle_waves")
	_grandmasterLog.BattleSeconds = field.NewInt64(tableName, "battle_seconds")
	_grandmasterLog.Date = field.NewString(tableName, "date")
	_grandmasterLog.EventAt = field.NewInt32(tableName, "event_at")

	_grandmasterLog.fillFieldMap()

	return _grandmasterLog
}

type grandmasterLog struct {
	grandmasterLogDo

	ALL           field.Asterisk
	ID            field.Int64
	UserID        field.Int64  // 用户id
	ServerID      field.Int32  // 服务器ID
	ChannelID     field.String // 渠道ID
	EventID       field.Int32  // 埋点id
	MatchSeconds  field.Int64  // 匹配时长
	DanScore      field.Int64  // 段位积分
	BattleWaves   field.Int64  // 战斗波数
	BattleSeconds field.Int64  // 战斗时长
	Date          field.String
	EventAt       field.Int32 // 埋点事件触发的时间

	fieldMap map[string]field.Expr
}

func (g grandmasterLog) Table(newTableName string) *grandmasterLog {
	g.grandmasterLogDo.UseTable(newTableName)
	return g.updateTableName(newTableName)
}

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

func (g *grandmasterLog) updateTableName(table string) *grandmasterLog {
	g.ALL = field.NewAsterisk(table)
	g.ID = field.NewInt64(table, "id")
	g.UserID = field.NewInt64(table, "user_id")
	g.ServerID = field.NewInt32(table, "server_id")
	g.ChannelID = field.NewString(table, "channel_id")
	g.EventID = field.NewInt32(table, "event_id")
	g.MatchSeconds = field.NewInt64(table, "match_seconds")
	g.DanScore = field.NewInt64(table, "dan_score")
	g.BattleWaves = field.NewInt64(table, "battle_waves")
	g.BattleSeconds = field.NewInt64(table, "battle_seconds")
	g.Date = field.NewString(table, "date")
	g.EventAt = field.NewInt32(table, "event_at")

	g.fillFieldMap()

	return g
}

func (g *grandmasterLog) 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 *grandmasterLog) fillFieldMap() {
	g.fieldMap = make(map[string]field.Expr, 11)
	g.fieldMap["id"] = g.ID
	g.fieldMap["user_id"] = g.UserID
	g.fieldMap["server_id"] = g.ServerID
	g.fieldMap["channel_id"] = g.ChannelID
	g.fieldMap["event_id"] = g.EventID
	g.fieldMap["match_seconds"] = g.MatchSeconds
	g.fieldMap["dan_score"] = g.DanScore
	g.fieldMap["battle_waves"] = g.BattleWaves
	g.fieldMap["battle_seconds"] = g.BattleSeconds
	g.fieldMap["date"] = g.Date
	g.fieldMap["event_at"] = g.EventAt
}

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

func (g grandmasterLog) replaceDB(db *gorm.DB) grandmasterLog {
	g.grandmasterLogDo.ReplaceDB(db)
	return g
}

type grandmasterLogDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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