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

	_reportDayAdvBasic.reportDayAdvBasicDo.UseDB(db, opts...)
	_reportDayAdvBasic.reportDayAdvBasicDo.UseModel(&model.ReportDayAdvBasic{})

	tableName := _reportDayAdvBasic.reportDayAdvBasicDo.TableName()
	_reportDayAdvBasic.ALL = field.NewAsterisk(tableName)
	_reportDayAdvBasic.ID = field.NewInt64(tableName, "id")
	_reportDayAdvBasic.Date = field.NewString(tableName, "date")
	_reportDayAdvBasic.PositionID = field.NewInt64(tableName, "position_id")
	_reportDayAdvBasic.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayAdvBasic.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayAdvBasic.Flag = field.NewInt32(tableName, "flag")
	_reportDayAdvBasic.Name = field.NewString(tableName, "name")
	_reportDayAdvBasic.ShowTimes = field.NewInt64(tableName, "show_times")
	_reportDayAdvBasic.ClickTimes = field.NewInt64(tableName, "click_times")
	_reportDayAdvBasic.RewardTimes = field.NewInt64(tableName, "reward_times")
	_reportDayAdvBasic.ShowUsers = field.NewInt64(tableName, "show_users")
	_reportDayAdvBasic.ClickUsers = field.NewInt64(tableName, "click_users")
	_reportDayAdvBasic.RewardUsers = field.NewInt64(tableName, "reward_users")
	_reportDayAdvBasic.CreatedAt = field.NewInt64(tableName, "created_at")
	_reportDayAdvBasic.UpdatedAt = field.NewInt64(tableName, "updated_at")

	_reportDayAdvBasic.fillFieldMap()

	return _reportDayAdvBasic
}

type reportDayAdvBasic struct {
	reportDayAdvBasicDo

	ALL         field.Asterisk
	ID          field.Int64
	Date        field.String
	PositionID  field.Int64  // 条件编号
	ChannelID   field.String // 渠道ID
	ServerID    field.Int32  // 服务器ID
	Flag        field.Int32
	Name        field.String // 条件名称
	ShowTimes   field.Int64
	ClickTimes  field.Int64
	RewardTimes field.Int64
	ShowUsers   field.Int64
	ClickUsers  field.Int64
	RewardUsers field.Int64
	CreatedAt   field.Int64
	UpdatedAt   field.Int64

	fieldMap map[string]field.Expr
}

func (r reportDayAdvBasic) Table(newTableName string) *reportDayAdvBasic {
	r.reportDayAdvBasicDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportDayAdvBasic) updateTableName(table string) *reportDayAdvBasic {
	r.ALL = field.NewAsterisk(table)
	r.ID = field.NewInt64(table, "id")
	r.Date = field.NewString(table, "date")
	r.PositionID = field.NewInt64(table, "position_id")
	r.ChannelID = field.NewString(table, "channel_id")
	r.ServerID = field.NewInt32(table, "server_id")
	r.Flag = field.NewInt32(table, "flag")
	r.Name = field.NewString(table, "name")
	r.ShowTimes = field.NewInt64(table, "show_times")
	r.ClickTimes = field.NewInt64(table, "click_times")
	r.RewardTimes = field.NewInt64(table, "reward_times")
	r.ShowUsers = field.NewInt64(table, "show_users")
	r.ClickUsers = field.NewInt64(table, "click_users")
	r.RewardUsers = field.NewInt64(table, "reward_users")
	r.CreatedAt = field.NewInt64(table, "created_at")
	r.UpdatedAt = field.NewInt64(table, "updated_at")

	r.fillFieldMap()

	return r
}

func (r *reportDayAdvBasic) 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 *reportDayAdvBasic) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 15)
	r.fieldMap["id"] = r.ID
	r.fieldMap["date"] = r.Date
	r.fieldMap["position_id"] = r.PositionID
	r.fieldMap["channel_id"] = r.ChannelID
	r.fieldMap["server_id"] = r.ServerID
	r.fieldMap["flag"] = r.Flag
	r.fieldMap["name"] = r.Name
	r.fieldMap["show_times"] = r.ShowTimes
	r.fieldMap["click_times"] = r.ClickTimes
	r.fieldMap["reward_times"] = r.RewardTimes
	r.fieldMap["show_users"] = r.ShowUsers
	r.fieldMap["click_users"] = r.ClickUsers
	r.fieldMap["reward_users"] = r.RewardUsers
	r.fieldMap["created_at"] = r.CreatedAt
	r.fieldMap["updated_at"] = r.UpdatedAt
}

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

func (r reportDayAdvBasic) replaceDB(db *gorm.DB) reportDayAdvBasic {
	r.reportDayAdvBasicDo.ReplaceDB(db)
	return r
}

type reportDayAdvBasicDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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