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

	_reportDayGrandmaster.reportDayGrandmasterDo.UseDB(db, opts...)
	_reportDayGrandmaster.reportDayGrandmasterDo.UseModel(&model.ReportDayGrandmaster{})

	tableName := _reportDayGrandmaster.reportDayGrandmasterDo.TableName()
	_reportDayGrandmaster.ALL = field.NewAsterisk(tableName)
	_reportDayGrandmaster.ID = field.NewInt64(tableName, "id")
	_reportDayGrandmaster.Date = field.NewString(tableName, "date")
	_reportDayGrandmaster.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayGrandmaster.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayGrandmaster.PlayerCount = field.NewInt64(tableName, "player_count")
	_reportDayGrandmaster.OpenPlayerCount = field.NewInt64(tableName, "open_player_count")
	_reportDayGrandmaster.PartCount = field.NewInt64(tableName, "part_count")
	_reportDayGrandmaster.AllMatchSeconds = field.NewInt64(tableName, "all_match_seconds")
	_reportDayGrandmaster.LeaveUsers = field.NewInt64(tableName, "leave_users")
	_reportDayGrandmaster.BattleWavesCount = field.NewInt64(tableName, "battle_waves_count")
	_reportDayGrandmaster.AllBattleSeconds = field.NewInt64(tableName, "all_battle_seconds")

	_reportDayGrandmaster.fillFieldMap()

	return _reportDayGrandmaster
}

type reportDayGrandmaster struct {
	reportDayGrandmasterDo

	ALL              field.Asterisk
	ID               field.Int64  // ID
	Date             field.String // 日期
	ChannelID        field.String // 渠道ID
	ServerID         field.Int32  // 服务器ID
	PlayerCount      field.Int64  // 参与人数
	OpenPlayerCount  field.Int64  // 活动开放玩家数量
	PartCount        field.Int64  // 参与次数
	AllMatchSeconds  field.Int64  // 总匹配时长
	LeaveUsers       field.Int64  // 离开人数
	BattleWavesCount field.Int64  // 战斗波数
	AllBattleSeconds field.Int64  // 总战斗时长

	fieldMap map[string]field.Expr
}

func (r reportDayGrandmaster) Table(newTableName string) *reportDayGrandmaster {
	r.reportDayGrandmasterDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

func (r reportDayGrandmaster) As(alias string) *reportDayGrandmaster {
	r.reportDayGrandmasterDo.DO = *(r.reportDayGrandmasterDo.As(alias).(*gen.DO))
	return r.updateTableName(alias)
}

func (r *reportDayGrandmaster) updateTableName(table string) *reportDayGrandmaster {
	r.ALL = field.NewAsterisk(table)
	r.ID = field.NewInt64(table, "id")
	r.Date = field.NewString(table, "date")
	r.ChannelID = field.NewString(table, "channel_id")
	r.ServerID = field.NewInt32(table, "server_id")
	r.PlayerCount = field.NewInt64(table, "player_count")
	r.OpenPlayerCount = field.NewInt64(table, "open_player_count")
	r.PartCount = field.NewInt64(table, "part_count")
	r.AllMatchSeconds = field.NewInt64(table, "all_match_seconds")
	r.LeaveUsers = field.NewInt64(table, "leave_users")
	r.BattleWavesCount = field.NewInt64(table, "battle_waves_count")
	r.AllBattleSeconds = field.NewInt64(table, "all_battle_seconds")

	r.fillFieldMap()

	return r
}

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

func (r *reportDayGrandmaster) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 11)
	r.fieldMap["id"] = r.ID
	r.fieldMap["date"] = r.Date
	r.fieldMap["channel_id"] = r.ChannelID
	r.fieldMap["server_id"] = r.ServerID
	r.fieldMap["player_count"] = r.PlayerCount
	r.fieldMap["open_player_count"] = r.OpenPlayerCount
	r.fieldMap["part_count"] = r.PartCount
	r.fieldMap["all_match_seconds"] = r.AllMatchSeconds
	r.fieldMap["leave_users"] = r.LeaveUsers
	r.fieldMap["battle_waves_count"] = r.BattleWavesCount
	r.fieldMap["all_battle_seconds"] = r.AllBattleSeconds
}

func (r reportDayGrandmaster) clone(db *gorm.DB) reportDayGrandmaster {
	r.reportDayGrandmasterDo.ReplaceConnPool(db.Statement.ConnPool)
	return r
}

func (r reportDayGrandmaster) replaceDB(db *gorm.DB) reportDayGrandmaster {
	r.reportDayGrandmasterDo.ReplaceDB(db)
	return r
}

type reportDayGrandmasterDo struct{ gen.DO }

func (r reportDayGrandmasterDo) Debug() *reportDayGrandmasterDo {
	return r.withDO(r.DO.Debug())
}

func (r reportDayGrandmasterDo) WithContext(ctx context.Context) *reportDayGrandmasterDo {
	return r.withDO(r.DO.WithContext(ctx))
}

func (r reportDayGrandmasterDo) ReadDB() *reportDayGrandmasterDo {
	return r.Clauses(dbresolver.Read)
}

func (r reportDayGrandmasterDo) WriteDB() *reportDayGrandmasterDo {
	return r.Clauses(dbresolver.Write)
}

func (r reportDayGrandmasterDo) Session(config *gorm.Session) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Session(config))
}

func (r reportDayGrandmasterDo) Clauses(conds ...clause.Expression) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Clauses(conds...))
}

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

func (r reportDayGrandmasterDo) Not(conds ...gen.Condition) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Not(conds...))
}

func (r reportDayGrandmasterDo) Or(conds ...gen.Condition) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Or(conds...))
}

func (r reportDayGrandmasterDo) Select(conds ...field.Expr) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Select(conds...))
}

func (r reportDayGrandmasterDo) Where(conds ...gen.Condition) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Where(conds...))
}

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

func (r reportDayGrandmasterDo) Order(conds ...field.Expr) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Order(conds...))
}

func (r reportDayGrandmasterDo) Distinct(cols ...field.Expr) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Distinct(cols...))
}

func (r reportDayGrandmasterDo) Omit(cols ...field.Expr) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Omit(cols...))
}

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

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

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

func (r reportDayGrandmasterDo) Group(cols ...field.Expr) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Group(cols...))
}

func (r reportDayGrandmasterDo) Having(conds ...gen.Condition) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Having(conds...))
}

func (r reportDayGrandmasterDo) Limit(limit int) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Limit(limit))
}

func (r reportDayGrandmasterDo) Offset(offset int) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Offset(offset))
}

func (r reportDayGrandmasterDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Scopes(funcs...))
}

func (r reportDayGrandmasterDo) Unscoped() *reportDayGrandmasterDo {
	return r.withDO(r.DO.Unscoped())
}

func (r reportDayGrandmasterDo) Create(values ...*model.ReportDayGrandmaster) error {
	if len(values) == 0 {
		return nil
	}
	return r.DO.Create(values)
}

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

func (r reportDayGrandmasterDo) First() (*model.ReportDayGrandmaster, error) {
	if result, err := r.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayGrandmaster), nil
	}
}

func (r reportDayGrandmasterDo) Take() (*model.ReportDayGrandmaster, error) {
	if result, err := r.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayGrandmaster), nil
	}
}

func (r reportDayGrandmasterDo) Last() (*model.ReportDayGrandmaster, error) {
	if result, err := r.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayGrandmaster), nil
	}
}

func (r reportDayGrandmasterDo) Find() ([]*model.ReportDayGrandmaster, error) {
	result, err := r.DO.Find()
	return result.([]*model.ReportDayGrandmaster), err
}

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

func (r reportDayGrandmasterDo) Attrs(attrs ...field.AssignExpr) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Attrs(attrs...))
}

func (r reportDayGrandmasterDo) Assign(attrs ...field.AssignExpr) *reportDayGrandmasterDo {
	return r.withDO(r.DO.Assign(attrs...))
}

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

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

func (r reportDayGrandmasterDo) FirstOrInit() (*model.ReportDayGrandmaster, error) {
	if result, err := r.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayGrandmaster), nil
	}
}

func (r reportDayGrandmasterDo) FirstOrCreate() (*model.ReportDayGrandmaster, error) {
	if result, err := r.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ReportDayGrandmaster), nil
	}
}

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

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

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

func (r reportDayGrandmasterDo) Scan(result interface{}) (err error) {
	return r.DO.Scan(result)
}

func (r reportDayGrandmasterDo) Delete(models ...*model.ReportDayGrandmaster) (result gen.ResultInfo, err error) {
	return r.DO.Delete(models)
}

func (r *reportDayGrandmasterDo) withDO(do gen.Dao) *reportDayGrandmasterDo {
	r.DO = *do.(*gen.DO)
	return r
}
