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

	_reportDayTreasure.reportDayTreasureDo.UseDB(db, opts...)
	_reportDayTreasure.reportDayTreasureDo.UseModel(&model.ReportDayTreasure{})

	tableName := _reportDayTreasure.reportDayTreasureDo.TableName()
	_reportDayTreasure.ALL = field.NewAsterisk(tableName)
	_reportDayTreasure.ID = field.NewInt64(tableName, "id")
	_reportDayTreasure.Date = field.NewString(tableName, "date")
	_reportDayTreasure.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayTreasure.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayTreasure.PlayerCount = field.NewInt64(tableName, "player_count")
	_reportDayTreasure.Output = field.NewString(tableName, "output")

	_reportDayTreasure.fillFieldMap()

	return _reportDayTreasure
}

type reportDayTreasure struct {
	reportDayTreasureDo

	ALL         field.Asterisk
	ID          field.Int64  // ID
	Date        field.String // 日期
	ChannelID   field.String // 渠道ID
	ServerID    field.Int32  // 服务器ID
	PlayerCount field.Int64  // 获得宝物碎片人数
	Output      field.String // 产出

	fieldMap map[string]field.Expr
}

func (r reportDayTreasure) Table(newTableName string) *reportDayTreasure {
	r.reportDayTreasureDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportDayTreasure) updateTableName(table string) *reportDayTreasure {
	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.PlayerCount = field.NewInt64(table, "player_count")
	r.Output = field.NewString(table, "output")

	r.fillFieldMap()

	return r
}

func (r *reportDayTreasure) 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 *reportDayTreasure) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 6)
	r.fieldMap["id"] = r.ID
	r.fieldMap["date"] = r.Date
	r.fieldMap["channel_id"] = r.ChannelID
	r.fieldMap["server_id"] = r.ServerID
	r.fieldMap["player_count"] = r.PlayerCount
	r.fieldMap["output"] = r.Output
}

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

func (r reportDayTreasure) replaceDB(db *gorm.DB) reportDayTreasure {
	r.reportDayTreasureDo.ReplaceDB(db)
	return r
}

type reportDayTreasureDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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