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

	_reportDayNewConv.reportDayNewConvDo.UseDB(db, opts...)
	_reportDayNewConv.reportDayNewConvDo.UseModel(&model.ReportDayNewConv{})

	tableName := _reportDayNewConv.reportDayNewConvDo.TableName()
	_reportDayNewConv.ALL = field.NewAsterisk(tableName)
	_reportDayNewConv.ID = field.NewInt64(tableName, "id")
	_reportDayNewConv.Date = field.NewString(tableName, "date")
	_reportDayNewConv.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayNewConv.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayNewConv.Wear1Users = field.NewInt64(tableName, "wear1_users")
	_reportDayNewConv.Wear2Users = field.NewInt64(tableName, "wear2_users")
	_reportDayNewConv.Wear3Users = field.NewInt64(tableName, "wear3_users")
	_reportDayNewConv.FirstChapterUsers = field.NewInt64(tableName, "first_chapter_users")
	_reportDayNewConv.Intensify1Users = field.NewInt64(tableName, "intensify1_users")
	_reportDayNewConv.Intensify2Users = field.NewInt64(tableName, "intensify2_users")
	_reportDayNewConv.Intensify3Users = field.NewInt64(tableName, "intensify3_users")
	_reportDayNewConv.Intensify4Users = field.NewInt64(tableName, "intensify4_users")
	_reportDayNewConv.Wear1Count = field.NewInt64(tableName, "wear1_count")
	_reportDayNewConv.Wear2Count = field.NewInt64(tableName, "wear2_count")
	_reportDayNewConv.Wear3Count = field.NewInt64(tableName, "wear3_count")
	_reportDayNewConv.FirstChapterCount = field.NewInt64(tableName, "first_chapter_count")
	_reportDayNewConv.Intensify1Count = field.NewInt64(tableName, "intensify1_count")
	_reportDayNewConv.Intensify2Count = field.NewInt64(tableName, "intensify2_count")
	_reportDayNewConv.Intensify3Count = field.NewInt64(tableName, "intensify3_count")
	_reportDayNewConv.Intensify4Count = field.NewInt64(tableName, "intensify4_count")

	_reportDayNewConv.fillFieldMap()

	return _reportDayNewConv
}

type reportDayNewConv struct {
	reportDayNewConvDo

	ALL               field.Asterisk
	ID                field.Int64
	Date              field.String
	ChannelID         field.String // 渠道ID
	ServerID          field.Int32  // 服务器ID
	Wear1Users        field.Int64
	Wear2Users        field.Int64
	Wear3Users        field.Int64
	FirstChapterUsers field.Int64
	Intensify1Users   field.Int64
	Intensify2Users   field.Int64
	Intensify3Users   field.Int64
	Intensify4Users   field.Int64
	Wear1Count        field.Int64
	Wear2Count        field.Int64
	Wear3Count        field.Int64
	FirstChapterCount field.Int64
	Intensify1Count   field.Int64
	Intensify2Count   field.Int64
	Intensify3Count   field.Int64
	Intensify4Count   field.Int64

	fieldMap map[string]field.Expr
}

func (r reportDayNewConv) Table(newTableName string) *reportDayNewConv {
	r.reportDayNewConvDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportDayNewConv) updateTableName(table string) *reportDayNewConv {
	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.Wear1Users = field.NewInt64(table, "wear1_users")
	r.Wear2Users = field.NewInt64(table, "wear2_users")
	r.Wear3Users = field.NewInt64(table, "wear3_users")
	r.FirstChapterUsers = field.NewInt64(table, "first_chapter_users")
	r.Intensify1Users = field.NewInt64(table, "intensify1_users")
	r.Intensify2Users = field.NewInt64(table, "intensify2_users")
	r.Intensify3Users = field.NewInt64(table, "intensify3_users")
	r.Intensify4Users = field.NewInt64(table, "intensify4_users")
	r.Wear1Count = field.NewInt64(table, "wear1_count")
	r.Wear2Count = field.NewInt64(table, "wear2_count")
	r.Wear3Count = field.NewInt64(table, "wear3_count")
	r.FirstChapterCount = field.NewInt64(table, "first_chapter_count")
	r.Intensify1Count = field.NewInt64(table, "intensify1_count")
	r.Intensify2Count = field.NewInt64(table, "intensify2_count")
	r.Intensify3Count = field.NewInt64(table, "intensify3_count")
	r.Intensify4Count = field.NewInt64(table, "intensify4_count")

	r.fillFieldMap()

	return r
}

func (r *reportDayNewConv) 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 *reportDayNewConv) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 20)
	r.fieldMap["id"] = r.ID
	r.fieldMap["date"] = r.Date
	r.fieldMap["channel_id"] = r.ChannelID
	r.fieldMap["server_id"] = r.ServerID
	r.fieldMap["wear1_users"] = r.Wear1Users
	r.fieldMap["wear2_users"] = r.Wear2Users
	r.fieldMap["wear3_users"] = r.Wear3Users
	r.fieldMap["first_chapter_users"] = r.FirstChapterUsers
	r.fieldMap["intensify1_users"] = r.Intensify1Users
	r.fieldMap["intensify2_users"] = r.Intensify2Users
	r.fieldMap["intensify3_users"] = r.Intensify3Users
	r.fieldMap["intensify4_users"] = r.Intensify4Users
	r.fieldMap["wear1_count"] = r.Wear1Count
	r.fieldMap["wear2_count"] = r.Wear2Count
	r.fieldMap["wear3_count"] = r.Wear3Count
	r.fieldMap["first_chapter_count"] = r.FirstChapterCount
	r.fieldMap["intensify1_count"] = r.Intensify1Count
	r.fieldMap["intensify2_count"] = r.Intensify2Count
	r.fieldMap["intensify3_count"] = r.Intensify3Count
	r.fieldMap["intensify4_count"] = r.Intensify4Count
}

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

func (r reportDayNewConv) replaceDB(db *gorm.DB) reportDayNewConv {
	r.reportDayNewConvDo.ReplaceDB(db)
	return r
}

type reportDayNewConvDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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