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

	_reportDayAdvSumm.reportDayAdvSummDo.UseDB(db, opts...)
	_reportDayAdvSumm.reportDayAdvSummDo.UseModel(&model.ReportDayAdvSumm{})

	tableName := _reportDayAdvSumm.reportDayAdvSummDo.TableName()
	_reportDayAdvSumm.ALL = field.NewAsterisk(tableName)
	_reportDayAdvSumm.ID = field.NewInt64(tableName, "id")
	_reportDayAdvSumm.Date = field.NewString(tableName, "date")
	_reportDayAdvSumm.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayAdvSumm.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayAdvSumm.Flag = field.NewInt32(tableName, "flag")
	_reportDayAdvSumm.RewardTimes = field.NewInt64(tableName, "reward_times")
	_reportDayAdvSumm.RewardUsers = field.NewInt64(tableName, "reward_users")
	_reportDayAdvSumm.NewTimes = field.NewInt64(tableName, "new_times")
	_reportDayAdvSumm.NewUsers = field.NewInt64(tableName, "new_users")
	_reportDayAdvSumm.OldTimes = field.NewInt64(tableName, "old_times")
	_reportDayAdvSumm.OldUsers = field.NewInt64(tableName, "old_users")

	_reportDayAdvSumm.fillFieldMap()

	return _reportDayAdvSumm
}

type reportDayAdvSumm struct {
	reportDayAdvSummDo

	ALL         field.Asterisk
	ID          field.Int64
	Date        field.String // 日期
	ChannelID   field.String // 渠道ID
	ServerID    field.Int32  // 服务器ID
	Flag        field.Int32
	RewardTimes field.Int64 // 总曝光次数
	RewardUsers field.Int64 // 总曝光人数
	NewTimes    field.Int64 // 新注册广告次数
	NewUsers    field.Int64 // 新注册广告人数
	OldTimes    field.Int64 // 老玩家广告次数
	OldUsers    field.Int64 // 老玩家广告人数

	fieldMap map[string]field.Expr
}

func (r reportDayAdvSumm) Table(newTableName string) *reportDayAdvSumm {
	r.reportDayAdvSummDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportDayAdvSumm) updateTableName(table string) *reportDayAdvSumm {
	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.Flag = field.NewInt32(table, "flag")
	r.RewardTimes = field.NewInt64(table, "reward_times")
	r.RewardUsers = field.NewInt64(table, "reward_users")
	r.NewTimes = field.NewInt64(table, "new_times")
	r.NewUsers = field.NewInt64(table, "new_users")
	r.OldTimes = field.NewInt64(table, "old_times")
	r.OldUsers = field.NewInt64(table, "old_users")

	r.fillFieldMap()

	return r
}

func (r *reportDayAdvSumm) 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 *reportDayAdvSumm) 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["flag"] = r.Flag
	r.fieldMap["reward_times"] = r.RewardTimes
	r.fieldMap["reward_users"] = r.RewardUsers
	r.fieldMap["new_times"] = r.NewTimes
	r.fieldMap["new_users"] = r.NewUsers
	r.fieldMap["old_times"] = r.OldTimes
	r.fieldMap["old_users"] = r.OldUsers
}

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

func (r reportDayAdvSumm) replaceDB(db *gorm.DB) reportDayAdvSumm {
	r.reportDayAdvSummDo.ReplaceDB(db)
	return r
}

type reportDayAdvSummDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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