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

	_sevenLog.sevenLogDo.UseDB(db, opts...)
	_sevenLog.sevenLogDo.UseModel(&model.SevenLog{})

	tableName := _sevenLog.sevenLogDo.TableName()
	_sevenLog.ALL = field.NewAsterisk(tableName)
	_sevenLog.ID = field.NewInt64(tableName, "id")
	_sevenLog.UserID = field.NewInt64(tableName, "user_id")
	_sevenLog.ServerID = field.NewInt32(tableName, "server_id")
	_sevenLog.EventID = field.NewInt32(tableName, "event_id")
	_sevenLog.UnlockDay = field.NewInt32(tableName, "unlock_day")
	_sevenLog.TaskID = field.NewInt32(tableName, "task_id")
	_sevenLog.UserCreatedAt = field.NewInt32(tableName, "user_created_at")
	_sevenLog.Date = field.NewString(tableName, "date")
	_sevenLog.EventAt = field.NewInt32(tableName, "event_at")
	_sevenLog.EventAtNs = field.NewInt64(tableName, "event_at_ns")

	_sevenLog.fillFieldMap()

	return _sevenLog
}

type sevenLog struct {
	sevenLogDo

	ALL           field.Asterisk
	ID            field.Int64
	UserID        field.Int64  // 用户ID
	ServerID      field.Int32  // 服务器ID
	EventID       field.Int32  // 事件ID
	UnlockDay     field.Int32  // 当天解锁天数
	TaskID        field.Int32  // 任务/奖励ID
	UserCreatedAt field.Int32  // 玩家注册时间
	Date          field.String // 触发日期 2005-01-02
	EventAt       field.Int32  // 触发时间戳
	EventAtNs     field.Int64  // 发生时间ns

	fieldMap map[string]field.Expr
}

func (s sevenLog) Table(newTableName string) *sevenLog {
	s.sevenLogDo.UseTable(newTableName)
	return s.updateTableName(newTableName)
}

func (s sevenLog) As(alias string) *sevenLog {
	s.sevenLogDo.DO = *(s.sevenLogDo.As(alias).(*gen.DO))
	return s.updateTableName(alias)
}

func (s *sevenLog) updateTableName(table string) *sevenLog {
	s.ALL = field.NewAsterisk(table)
	s.ID = field.NewInt64(table, "id")
	s.UserID = field.NewInt64(table, "user_id")
	s.ServerID = field.NewInt32(table, "server_id")
	s.EventID = field.NewInt32(table, "event_id")
	s.UnlockDay = field.NewInt32(table, "unlock_day")
	s.TaskID = field.NewInt32(table, "task_id")
	s.UserCreatedAt = field.NewInt32(table, "user_created_at")
	s.Date = field.NewString(table, "date")
	s.EventAt = field.NewInt32(table, "event_at")
	s.EventAtNs = field.NewInt64(table, "event_at_ns")

	s.fillFieldMap()

	return s
}

func (s *sevenLog) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
	_f, ok := s.fieldMap[fieldName]
	if !ok || _f == nil {
		return nil, false
	}
	_oe, ok := _f.(field.OrderExpr)
	return _oe, ok
}

func (s *sevenLog) fillFieldMap() {
	s.fieldMap = make(map[string]field.Expr, 10)
	s.fieldMap["id"] = s.ID
	s.fieldMap["user_id"] = s.UserID
	s.fieldMap["server_id"] = s.ServerID
	s.fieldMap["event_id"] = s.EventID
	s.fieldMap["unlock_day"] = s.UnlockDay
	s.fieldMap["task_id"] = s.TaskID
	s.fieldMap["user_created_at"] = s.UserCreatedAt
	s.fieldMap["date"] = s.Date
	s.fieldMap["event_at"] = s.EventAt
	s.fieldMap["event_at_ns"] = s.EventAtNs
}

func (s sevenLog) clone(db *gorm.DB) sevenLog {
	s.sevenLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return s
}

func (s sevenLog) replaceDB(db *gorm.DB) sevenLog {
	s.sevenLogDo.ReplaceDB(db)
	return s
}

type sevenLogDo struct{ gen.DO }

func (s sevenLogDo) Debug() *sevenLogDo {
	return s.withDO(s.DO.Debug())
}

func (s sevenLogDo) WithContext(ctx context.Context) *sevenLogDo {
	return s.withDO(s.DO.WithContext(ctx))
}

func (s sevenLogDo) ReadDB() *sevenLogDo {
	return s.Clauses(dbresolver.Read)
}

func (s sevenLogDo) WriteDB() *sevenLogDo {
	return s.Clauses(dbresolver.Write)
}

func (s sevenLogDo) Session(config *gorm.Session) *sevenLogDo {
	return s.withDO(s.DO.Session(config))
}

func (s sevenLogDo) Clauses(conds ...clause.Expression) *sevenLogDo {
	return s.withDO(s.DO.Clauses(conds...))
}

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

func (s sevenLogDo) Not(conds ...gen.Condition) *sevenLogDo {
	return s.withDO(s.DO.Not(conds...))
}

func (s sevenLogDo) Or(conds ...gen.Condition) *sevenLogDo {
	return s.withDO(s.DO.Or(conds...))
}

func (s sevenLogDo) Select(conds ...field.Expr) *sevenLogDo {
	return s.withDO(s.DO.Select(conds...))
}

func (s sevenLogDo) Where(conds ...gen.Condition) *sevenLogDo {
	return s.withDO(s.DO.Where(conds...))
}

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

func (s sevenLogDo) Order(conds ...field.Expr) *sevenLogDo {
	return s.withDO(s.DO.Order(conds...))
}

func (s sevenLogDo) Distinct(cols ...field.Expr) *sevenLogDo {
	return s.withDO(s.DO.Distinct(cols...))
}

func (s sevenLogDo) Omit(cols ...field.Expr) *sevenLogDo {
	return s.withDO(s.DO.Omit(cols...))
}

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

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

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

func (s sevenLogDo) Group(cols ...field.Expr) *sevenLogDo {
	return s.withDO(s.DO.Group(cols...))
}

func (s sevenLogDo) Having(conds ...gen.Condition) *sevenLogDo {
	return s.withDO(s.DO.Having(conds...))
}

func (s sevenLogDo) Limit(limit int) *sevenLogDo {
	return s.withDO(s.DO.Limit(limit))
}

func (s sevenLogDo) Offset(offset int) *sevenLogDo {
	return s.withDO(s.DO.Offset(offset))
}

func (s sevenLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *sevenLogDo {
	return s.withDO(s.DO.Scopes(funcs...))
}

func (s sevenLogDo) Unscoped() *sevenLogDo {
	return s.withDO(s.DO.Unscoped())
}

func (s sevenLogDo) Create(values ...*model.SevenLog) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Create(values)
}

func (s sevenLogDo) CreateInBatches(values []*model.SevenLog, batchSize int) error {
	return s.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 (s sevenLogDo) Save(values ...*model.SevenLog) error {
	if len(values) == 0 {
		return nil
	}
	return s.DO.Save(values)
}

func (s sevenLogDo) First() (*model.SevenLog, error) {
	if result, err := s.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.SevenLog), nil
	}
}

func (s sevenLogDo) Take() (*model.SevenLog, error) {
	if result, err := s.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.SevenLog), nil
	}
}

func (s sevenLogDo) Last() (*model.SevenLog, error) {
	if result, err := s.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.SevenLog), nil
	}
}

func (s sevenLogDo) Find() ([]*model.SevenLog, error) {
	result, err := s.DO.Find()
	return result.([]*model.SevenLog), err
}

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

func (s sevenLogDo) Attrs(attrs ...field.AssignExpr) *sevenLogDo {
	return s.withDO(s.DO.Attrs(attrs...))
}

func (s sevenLogDo) Assign(attrs ...field.AssignExpr) *sevenLogDo {
	return s.withDO(s.DO.Assign(attrs...))
}

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

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

func (s sevenLogDo) FirstOrInit() (*model.SevenLog, error) {
	if result, err := s.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.SevenLog), nil
	}
}

func (s sevenLogDo) FirstOrCreate() (*model.SevenLog, error) {
	if result, err := s.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.SevenLog), nil
	}
}

func (s sevenLogDo) FindByPage(offset int, limit int) (result []*model.SevenLog, count int64, err error) {
	result, err = s.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 = s.Offset(-1).Limit(-1).Count()
	return
}

func (s sevenLogDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
	count, err = s.Count()
	if err != nil {
		return
	}

	err = s.Offset(offset).Limit(limit).Scan(result)
	return
}

func (s sevenLogDo) Scan(result interface{}) (err error) {
	return s.DO.Scan(result)
}

func (s sevenLogDo) Delete(models ...*model.SevenLog) (result gen.ResultInfo, err error) {
	return s.DO.Delete(models)
}

func (s *sevenLogDo) withDO(do gen.Dao) *sevenLogDo {
	s.DO = *do.(*gen.DO)
	return s
}
