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

	_reportDayBasic.reportDayBasicDo.UseDB(db, opts...)
	_reportDayBasic.reportDayBasicDo.UseModel(&model.ReportDayBasic{})

	tableName := _reportDayBasic.reportDayBasicDo.TableName()
	_reportDayBasic.ALL = field.NewAsterisk(tableName)
	_reportDayBasic.ID = field.NewInt64(tableName, "id")
	_reportDayBasic.Date = field.NewString(tableName, "date")
	_reportDayBasic.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayBasic.Flag = field.NewInt32(tableName, "flag")
	_reportDayBasic.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayBasic.NewCount = field.NewInt64(tableName, "new_count")
	_reportDayBasic.ValidCount = field.NewInt64(tableName, "valid_count")
	_reportDayBasic.ActiveCount = field.NewInt64(tableName, "active_count")
	_reportDayBasic.OldCount = field.NewInt64(tableName, "old_count")
	_reportDayBasic.NewDuration = field.NewInt64(tableName, "new_duration")
	_reportDayBasic.ValidDuration = field.NewInt64(tableName, "valid_duration")
	_reportDayBasic.ActiveDuration = field.NewInt64(tableName, "active_duration")
	_reportDayBasic.Active1Day = field.NewInt64(tableName, "active_1_day")
	_reportDayBasic.Active2Day = field.NewInt64(tableName, "active_2_day")
	_reportDayBasic.Active3Day = field.NewInt64(tableName, "active_3_day")
	_reportDayBasic.Active4Day = field.NewInt64(tableName, "active_4_day")
	_reportDayBasic.Active5Day = field.NewInt64(tableName, "active_5_day")
	_reportDayBasic.Active6Day = field.NewInt64(tableName, "active_6_day")
	_reportDayBasic.Active7Day = field.NewInt64(tableName, "active_7_day")
	_reportDayBasic.Active14Day = field.NewInt64(tableName, "active_14_day")
	_reportDayBasic.Active30Day = field.NewInt64(tableName, "active_30_day")
	_reportDayBasic.C1 = field.NewInt64(tableName, "c1")
	_reportDayBasic.C2 = field.NewInt64(tableName, "c2")
	_reportDayBasic.C3 = field.NewInt64(tableName, "c3")
	_reportDayBasic.C4 = field.NewInt64(tableName, "c4")
	_reportDayBasic.C5 = field.NewInt64(tableName, "c5")
	_reportDayBasic.C6 = field.NewInt64(tableName, "c6")
	_reportDayBasic.C7 = field.NewInt64(tableName, "c7")
	_reportDayBasic.C14 = field.NewInt64(tableName, "c14")
	_reportDayBasic.C30 = field.NewInt64(tableName, "c30")
	_reportDayBasic.CreatedAt = field.NewInt32(tableName, "created_at")
	_reportDayBasic.UpdatedAt = field.NewInt32(tableName, "updated_at")

	_reportDayBasic.fillFieldMap()

	return _reportDayBasic
}

type reportDayBasic struct {
	reportDayBasicDo

	ALL            field.Asterisk
	ID             field.Int64
	Date           field.String
	ChannelID      field.String // 渠道ID
	Flag           field.Int32
	ServerID       field.Int32 // 服务器ID
	NewCount       field.Int64
	ValidCount     field.Int64 // 有效用户
	ActiveCount    field.Int64
	OldCount       field.Int64 // 老玩家数量
	NewDuration    field.Int64 // 新增用户的平均时长
	ValidDuration  field.Int64
	ActiveDuration field.Int64 // 活跃用户的平均时长
	Active1Day     field.Int64
	Active2Day     field.Int64
	Active3Day     field.Int64
	Active4Day     field.Int64
	Active5Day     field.Int64
	Active6Day     field.Int64
	Active7Day     field.Int64
	Active14Day    field.Int64
	Active30Day    field.Int64
	C1             field.Int64
	C2             field.Int64
	C3             field.Int64
	C4             field.Int64
	C5             field.Int64
	C6             field.Int64
	C7             field.Int64
	C14            field.Int64
	C30            field.Int64
	CreatedAt      field.Int32
	UpdatedAt      field.Int32

	fieldMap map[string]field.Expr
}

func (r reportDayBasic) Table(newTableName string) *reportDayBasic {
	r.reportDayBasicDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportDayBasic) updateTableName(table string) *reportDayBasic {
	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.Flag = field.NewInt32(table, "flag")
	r.ServerID = field.NewInt32(table, "server_id")
	r.NewCount = field.NewInt64(table, "new_count")
	r.ValidCount = field.NewInt64(table, "valid_count")
	r.ActiveCount = field.NewInt64(table, "active_count")
	r.OldCount = field.NewInt64(table, "old_count")
	r.NewDuration = field.NewInt64(table, "new_duration")
	r.ValidDuration = field.NewInt64(table, "valid_duration")
	r.ActiveDuration = field.NewInt64(table, "active_duration")
	r.Active1Day = field.NewInt64(table, "active_1_day")
	r.Active2Day = field.NewInt64(table, "active_2_day")
	r.Active3Day = field.NewInt64(table, "active_3_day")
	r.Active4Day = field.NewInt64(table, "active_4_day")
	r.Active5Day = field.NewInt64(table, "active_5_day")
	r.Active6Day = field.NewInt64(table, "active_6_day")
	r.Active7Day = field.NewInt64(table, "active_7_day")
	r.Active14Day = field.NewInt64(table, "active_14_day")
	r.Active30Day = field.NewInt64(table, "active_30_day")
	r.C1 = field.NewInt64(table, "c1")
	r.C2 = field.NewInt64(table, "c2")
	r.C3 = field.NewInt64(table, "c3")
	r.C4 = field.NewInt64(table, "c4")
	r.C5 = field.NewInt64(table, "c5")
	r.C6 = field.NewInt64(table, "c6")
	r.C7 = field.NewInt64(table, "c7")
	r.C14 = field.NewInt64(table, "c14")
	r.C30 = field.NewInt64(table, "c30")
	r.CreatedAt = field.NewInt32(table, "created_at")
	r.UpdatedAt = field.NewInt32(table, "updated_at")

	r.fillFieldMap()

	return r
}

func (r *reportDayBasic) 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 *reportDayBasic) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 32)
	r.fieldMap["id"] = r.ID
	r.fieldMap["date"] = r.Date
	r.fieldMap["channel_id"] = r.ChannelID
	r.fieldMap["flag"] = r.Flag
	r.fieldMap["server_id"] = r.ServerID
	r.fieldMap["new_count"] = r.NewCount
	r.fieldMap["valid_count"] = r.ValidCount
	r.fieldMap["active_count"] = r.ActiveCount
	r.fieldMap["old_count"] = r.OldCount
	r.fieldMap["new_duration"] = r.NewDuration
	r.fieldMap["valid_duration"] = r.ValidDuration
	r.fieldMap["active_duration"] = r.ActiveDuration
	r.fieldMap["active_1_day"] = r.Active1Day
	r.fieldMap["active_2_day"] = r.Active2Day
	r.fieldMap["active_3_day"] = r.Active3Day
	r.fieldMap["active_4_day"] = r.Active4Day
	r.fieldMap["active_5_day"] = r.Active5Day
	r.fieldMap["active_6_day"] = r.Active6Day
	r.fieldMap["active_7_day"] = r.Active7Day
	r.fieldMap["active_14_day"] = r.Active14Day
	r.fieldMap["active_30_day"] = r.Active30Day
	r.fieldMap["c1"] = r.C1
	r.fieldMap["c2"] = r.C2
	r.fieldMap["c3"] = r.C3
	r.fieldMap["c4"] = r.C4
	r.fieldMap["c5"] = r.C5
	r.fieldMap["c6"] = r.C6
	r.fieldMap["c7"] = r.C7
	r.fieldMap["c14"] = r.C14
	r.fieldMap["c30"] = r.C30
	r.fieldMap["created_at"] = r.CreatedAt
	r.fieldMap["updated_at"] = r.UpdatedAt
}

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

func (r reportDayBasic) replaceDB(db *gorm.DB) reportDayBasic {
	r.reportDayBasicDo.ReplaceDB(db)
	return r
}

type reportDayBasicDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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