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

	_reportDayLimitgift.reportDayLimitgiftDo.UseDB(db, opts...)
	_reportDayLimitgift.reportDayLimitgiftDo.UseModel(&model.ReportDayLimitgift{})

	tableName := _reportDayLimitgift.reportDayLimitgiftDo.TableName()
	_reportDayLimitgift.ALL = field.NewAsterisk(tableName)
	_reportDayLimitgift.ID = field.NewInt64(tableName, "id")
	_reportDayLimitgift.Date = field.NewString(tableName, "date")
	_reportDayLimitgift.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayLimitgift.ServerID = field.NewInt64(tableName, "server_id")
	_reportDayLimitgift.GoodsID = field.NewInt64(tableName, "goods_id")
	_reportDayLimitgift.ShowCount = field.NewInt64(tableName, "show_count")
	_reportDayLimitgift.PayCount = field.NewInt64(tableName, "pay_count")

	_reportDayLimitgift.fillFieldMap()

	return _reportDayLimitgift
}

type reportDayLimitgift struct {
	reportDayLimitgiftDo

	ALL       field.Asterisk
	ID        field.Int64  // ID
	Date      field.String // 日期
	ChannelID field.String // 渠道ID
	ServerID  field.Int64  // 服务器ID
	GoodsID   field.Int64  // 商品ID
	ShowCount field.Int64  // 出现次数
	PayCount  field.Int64  // 购买次数

	fieldMap map[string]field.Expr
}

func (r reportDayLimitgift) Table(newTableName string) *reportDayLimitgift {
	r.reportDayLimitgiftDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportDayLimitgift) updateTableName(table string) *reportDayLimitgift {
	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.NewInt64(table, "server_id")
	r.GoodsID = field.NewInt64(table, "goods_id")
	r.ShowCount = field.NewInt64(table, "show_count")
	r.PayCount = field.NewInt64(table, "pay_count")

	r.fillFieldMap()

	return r
}

func (r *reportDayLimitgift) 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 *reportDayLimitgift) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 7)
	r.fieldMap["id"] = r.ID
	r.fieldMap["date"] = r.Date
	r.fieldMap["channel_id"] = r.ChannelID
	r.fieldMap["server_id"] = r.ServerID
	r.fieldMap["goods_id"] = r.GoodsID
	r.fieldMap["show_count"] = r.ShowCount
	r.fieldMap["pay_count"] = r.PayCount
}

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

func (r reportDayLimitgift) replaceDB(db *gorm.DB) reportDayLimitgift {
	r.reportDayLimitgiftDo.ReplaceDB(db)
	return r
}

type reportDayLimitgiftDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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