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

	_reportDayChapterPass.reportDayChapterPassDo.UseDB(db, opts...)
	_reportDayChapterPass.reportDayChapterPassDo.UseModel(&model.ReportDayChapterPass{})

	tableName := _reportDayChapterPass.reportDayChapterPassDo.TableName()
	_reportDayChapterPass.ALL = field.NewAsterisk(tableName)
	_reportDayChapterPass.ID = field.NewInt64(tableName, "id")
	_reportDayChapterPass.Date = field.NewString(tableName, "date")
	_reportDayChapterPass.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayChapterPass.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayChapterPass.Data = field.NewString(tableName, "data")
	_reportDayChapterPass.RolesData = field.NewString(tableName, "roles_data")
	_reportDayChapterPass.Flag = field.NewInt32(tableName, "flag")

	_reportDayChapterPass.fillFieldMap()

	return _reportDayChapterPass
}

type reportDayChapterPass struct {
	reportDayChapterPassDo

	ALL       field.Asterisk
	ID        field.Int64
	Date      field.String
	ChannelID field.String // 渠道ID
	ServerID  field.Int32  // 服务器ID
	Data      field.String // 每个章节的通关率 ，json表示
	RolesData field.String
	Flag      field.Int32

	fieldMap map[string]field.Expr
}

func (r reportDayChapterPass) Table(newTableName string) *reportDayChapterPass {
	r.reportDayChapterPassDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportDayChapterPass) updateTableName(table string) *reportDayChapterPass {
	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.Data = field.NewString(table, "data")
	r.RolesData = field.NewString(table, "roles_data")
	r.Flag = field.NewInt32(table, "flag")

	r.fillFieldMap()

	return r
}

func (r *reportDayChapterPass) 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 *reportDayChapterPass) 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["data"] = r.Data
	r.fieldMap["roles_data"] = r.RolesData
	r.fieldMap["flag"] = r.Flag
}

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

func (r reportDayChapterPass) replaceDB(db *gorm.DB) reportDayChapterPass {
	r.reportDayChapterPassDo.ReplaceDB(db)
	return r
}

type reportDayChapterPassDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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