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

	_reportEvent.reportEventDo.UseDB(db, opts...)
	_reportEvent.reportEventDo.UseModel(&model.ReportEvent{})

	tableName := _reportEvent.reportEventDo.TableName()
	_reportEvent.ALL = field.NewAsterisk(tableName)
	_reportEvent.ID = field.NewInt64(tableName, "id")
	_reportEvent.EventID = field.NewInt64(tableName, "event_id")
	_reportEvent.EventName = field.NewString(tableName, "event_name")
	_reportEvent.ChapterID = field.NewInt64(tableName, "chapter_id")
	_reportEvent.Extra = field.NewString(tableName, "extra")
	_reportEvent.RoomID = field.NewInt64(tableName, "room_id")
	_reportEvent.Difficulty = field.NewInt64(tableName, "difficulty")

	_reportEvent.fillFieldMap()

	return _reportEvent
}

type reportEvent struct {
	reportEventDo

	ALL        field.Asterisk
	ID         field.Int64
	EventID    field.Int64
	EventName  field.String
	ChapterID  field.Int64
	Extra      field.String
	RoomID     field.Int64
	Difficulty field.Int64

	fieldMap map[string]field.Expr
}

func (r reportEvent) Table(newTableName string) *reportEvent {
	r.reportEventDo.UseTable(newTableName)
	return r.updateTableName(newTableName)
}

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

func (r *reportEvent) updateTableName(table string) *reportEvent {
	r.ALL = field.NewAsterisk(table)
	r.ID = field.NewInt64(table, "id")
	r.EventID = field.NewInt64(table, "event_id")
	r.EventName = field.NewString(table, "event_name")
	r.ChapterID = field.NewInt64(table, "chapter_id")
	r.Extra = field.NewString(table, "extra")
	r.RoomID = field.NewInt64(table, "room_id")
	r.Difficulty = field.NewInt64(table, "difficulty")

	r.fillFieldMap()

	return r
}

func (r *reportEvent) 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 *reportEvent) fillFieldMap() {
	r.fieldMap = make(map[string]field.Expr, 7)
	r.fieldMap["id"] = r.ID
	r.fieldMap["event_id"] = r.EventID
	r.fieldMap["event_name"] = r.EventName
	r.fieldMap["chapter_id"] = r.ChapterID
	r.fieldMap["extra"] = r.Extra
	r.fieldMap["room_id"] = r.RoomID
	r.fieldMap["difficulty"] = r.Difficulty
}

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

func (r reportEvent) replaceDB(db *gorm.DB) reportEvent {
	r.reportEventDo.ReplaceDB(db)
	return r
}

type reportEventDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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