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

	_reportDayEventBasic.reportDayEventBasicDo.UseDB(db, opts...)
	_reportDayEventBasic.reportDayEventBasicDo.UseModel(&model.ReportDayEventBasic{})

	tableName := _reportDayEventBasic.reportDayEventBasicDo.TableName()
	_reportDayEventBasic.ALL = field.NewAsterisk(tableName)
	_reportDayEventBasic.ID = field.NewInt64(tableName, "id")
	_reportDayEventBasic.Date = field.NewString(tableName, "date")
	_reportDayEventBasic.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayEventBasic.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayEventBasic.ConditionID = field.NewInt64(tableName, "condition_id")
	_reportDayEventBasic.Name = field.NewString(tableName, "name")
	_reportDayEventBasic.Count_ = field.NewInt64(tableName, "count")
	_reportDayEventBasic.Active1Day = field.NewInt64(tableName, "active_1_day")
	_reportDayEventBasic.Active2Day = field.NewInt64(tableName, "active_2_day")
	_reportDayEventBasic.Active3Day = field.NewInt64(tableName, "active_3_day")
	_reportDayEventBasic.Active4Day = field.NewInt64(tableName, "active_4_day")
	_reportDayEventBasic.Active5Day = field.NewInt64(tableName, "active_5_day")
	_reportDayEventBasic.Active6Day = field.NewInt64(tableName, "active_6_day")
	_reportDayEventBasic.Active7Day = field.NewInt64(tableName, "active_7_day")
	_reportDayEventBasic.Active14Day = field.NewInt64(tableName, "active_14_day")
	_reportDayEventBasic.Active30Day = field.NewInt64(tableName, "active_30_day")
	_reportDayEventBasic.CreatedAt = field.NewInt32(tableName, "created_at")
	_reportDayEventBasic.UpdatedAt = field.NewInt32(tableName, "updated_at")
	_reportDayEventBasic.Flag = field.NewInt32(tableName, "flag")

	_reportDayEventBasic.fillFieldMap()

	return _reportDayEventBasic
}

type reportDayEventBasic struct {
	reportDayEventBasicDo

	ALL         field.Asterisk
	ID          field.Int64
	Date        field.String
	ChannelID   field.String // 渠道ID
	ServerID    field.Int32  // 服务器ID
	ConditionID field.Int64  // 条件编号
	Name        field.String // 条件名称
	Count_      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
	CreatedAt   field.Int32
	UpdatedAt   field.Int32
	Flag        field.Int32

	fieldMap map[string]field.Expr
}

func (r reportDayEventBasic) Table(newTableName string) *reportDayEventBasic {
	r.reportDayEventBasicDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportDayEventBasic) updateTableName(table string) *reportDayEventBasic {
	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.ConditionID = field.NewInt64(table, "condition_id")
	r.Name = field.NewString(table, "name")
	r.Count_ = field.NewInt64(table, "count")
	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.CreatedAt = field.NewInt32(table, "created_at")
	r.UpdatedAt = field.NewInt32(table, "updated_at")
	r.Flag = field.NewInt32(table, "flag")

	r.fillFieldMap()

	return r
}

func (r *reportDayEventBasic) 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 *reportDayEventBasic) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 19)
	r.fieldMap["id"] = r.ID
	r.fieldMap["date"] = r.Date
	r.fieldMap["channel_id"] = r.ChannelID
	r.fieldMap["server_id"] = r.ServerID
	r.fieldMap["condition_id"] = r.ConditionID
	r.fieldMap["name"] = r.Name
	r.fieldMap["count"] = r.Count_
	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["created_at"] = r.CreatedAt
	r.fieldMap["updated_at"] = r.UpdatedAt
	r.fieldMap["flag"] = r.Flag
}

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

func (r reportDayEventBasic) replaceDB(db *gorm.DB) reportDayEventBasic {
	r.reportDayEventBasicDo.ReplaceDB(db)
	return r
}

type reportDayEventBasicDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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