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

	_reportDayHaveRole.reportDayHaveRoleDo.UseDB(db, opts...)
	_reportDayHaveRole.reportDayHaveRoleDo.UseModel(&model.ReportDayHaveRole{})

	tableName := _reportDayHaveRole.reportDayHaveRoleDo.TableName()
	_reportDayHaveRole.ALL = field.NewAsterisk(tableName)
	_reportDayHaveRole.ID = field.NewInt64(tableName, "id")
	_reportDayHaveRole.Date = field.NewString(tableName, "date")
	_reportDayHaveRole.ChannelID = field.NewString(tableName, "channel_id")
	_reportDayHaveRole.ServerID = field.NewInt32(tableName, "server_id")
	_reportDayHaveRole.Data = field.NewString(tableName, "data")

	_reportDayHaveRole.fillFieldMap()

	return _reportDayHaveRole
}

type reportDayHaveRole struct {
	reportDayHaveRoleDo

	ALL       field.Asterisk
	ID        field.Int64
	Date      field.String
	ChannelID field.String // 渠道ID
	ServerID  field.Int32  // 服务器ID
	Data      field.String // 拥有角色数据

	fieldMap map[string]field.Expr
}

func (r reportDayHaveRole) Table(newTableName string) *reportDayHaveRole {
	r.reportDayHaveRoleDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportDayHaveRole) updateTableName(table string) *reportDayHaveRole {
	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.fillFieldMap()

	return r
}

func (r *reportDayHaveRole) 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 *reportDayHaveRole) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 5)
	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
}

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

func (r reportDayHaveRole) replaceDB(db *gorm.DB) reportDayHaveRole {
	r.reportDayHaveRoleDo.ReplaceDB(db)
	return r
}

type reportDayHaveRoleDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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