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

	_limitgiftLog.limitgiftLogDo.UseDB(db, opts...)
	_limitgiftLog.limitgiftLogDo.UseModel(&model.LimitgiftLog{})

	tableName := _limitgiftLog.limitgiftLogDo.TableName()
	_limitgiftLog.ALL = field.NewAsterisk(tableName)
	_limitgiftLog.ID = field.NewInt64(tableName, "id")
	_limitgiftLog.UserID = field.NewInt64(tableName, "user_id")
	_limitgiftLog.ServerID = field.NewInt32(tableName, "server_id")
	_limitgiftLog.EventID = field.NewInt32(tableName, "event_id")
	_limitgiftLog.GoodsID = field.NewInt32(tableName, "goods_id")
	_limitgiftLog.Date = field.NewString(tableName, "date")
	_limitgiftLog.EventAt = field.NewInt32(tableName, "event_at")
	_limitgiftLog.EventAtNs = field.NewInt64(tableName, "event_at_ns")

	_limitgiftLog.fillFieldMap()

	return _limitgiftLog
}

type limitgiftLog struct {
	limitgiftLogDo

	ALL       field.Asterisk
	ID        field.Int64
	UserID    field.Int64 // 用户id
	ServerID  field.Int32 // 服务器ID
	EventID   field.Int32
	GoodsID   field.Int32  // 物品id
	Date      field.String // 触发日期 2005-01-02
	EventAt   field.Int32  // 触发时间戳
	EventAtNs field.Int64  // 发生时间ns

	fieldMap map[string]field.Expr
}

func (l limitgiftLog) Table(newTableName string) *limitgiftLog {
	l.limitgiftLogDo.UseTable(newTableName)
	return l.updateTableName(newTableName)
}

func (l limitgiftLog) As(alias string) *limitgiftLog {
	l.limitgiftLogDo.DO = *(l.limitgiftLogDo.As(alias).(*gen.DO))
	return l.updateTableName(alias)
}

func (l *limitgiftLog) updateTableName(table string) *limitgiftLog {
	l.ALL = field.NewAsterisk(table)
	l.ID = field.NewInt64(table, "id")
	l.UserID = field.NewInt64(table, "user_id")
	l.ServerID = field.NewInt32(table, "server_id")
	l.EventID = field.NewInt32(table, "event_id")
	l.GoodsID = field.NewInt32(table, "goods_id")
	l.Date = field.NewString(table, "date")
	l.EventAt = field.NewInt32(table, "event_at")
	l.EventAtNs = field.NewInt64(table, "event_at_ns")

	l.fillFieldMap()

	return l
}

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

func (l *limitgiftLog) fillFieldMap() {
	l.fieldMap = make(map[string]field.Expr, 8)
	l.fieldMap["id"] = l.ID
	l.fieldMap["user_id"] = l.UserID
	l.fieldMap["server_id"] = l.ServerID
	l.fieldMap["event_id"] = l.EventID
	l.fieldMap["goods_id"] = l.GoodsID
	l.fieldMap["date"] = l.Date
	l.fieldMap["event_at"] = l.EventAt
	l.fieldMap["event_at_ns"] = l.EventAtNs
}

func (l limitgiftLog) clone(db *gorm.DB) limitgiftLog {
	l.limitgiftLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return l
}

func (l limitgiftLog) replaceDB(db *gorm.DB) limitgiftLog {
	l.limitgiftLogDo.ReplaceDB(db)
	return l
}

type limitgiftLogDo struct{ gen.DO }

func (l limitgiftLogDo) Debug() *limitgiftLogDo {
	return l.withDO(l.DO.Debug())
}

func (l limitgiftLogDo) WithContext(ctx context.Context) *limitgiftLogDo {
	return l.withDO(l.DO.WithContext(ctx))
}

func (l limitgiftLogDo) ReadDB() *limitgiftLogDo {
	return l.Clauses(dbresolver.Read)
}

func (l limitgiftLogDo) WriteDB() *limitgiftLogDo {
	return l.Clauses(dbresolver.Write)
}

func (l limitgiftLogDo) Session(config *gorm.Session) *limitgiftLogDo {
	return l.withDO(l.DO.Session(config))
}

func (l limitgiftLogDo) Clauses(conds ...clause.Expression) *limitgiftLogDo {
	return l.withDO(l.DO.Clauses(conds...))
}

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

func (l limitgiftLogDo) Not(conds ...gen.Condition) *limitgiftLogDo {
	return l.withDO(l.DO.Not(conds...))
}

func (l limitgiftLogDo) Or(conds ...gen.Condition) *limitgiftLogDo {
	return l.withDO(l.DO.Or(conds...))
}

func (l limitgiftLogDo) Select(conds ...field.Expr) *limitgiftLogDo {
	return l.withDO(l.DO.Select(conds...))
}

func (l limitgiftLogDo) Where(conds ...gen.Condition) *limitgiftLogDo {
	return l.withDO(l.DO.Where(conds...))
}

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

func (l limitgiftLogDo) Order(conds ...field.Expr) *limitgiftLogDo {
	return l.withDO(l.DO.Order(conds...))
}

func (l limitgiftLogDo) Distinct(cols ...field.Expr) *limitgiftLogDo {
	return l.withDO(l.DO.Distinct(cols...))
}

func (l limitgiftLogDo) Omit(cols ...field.Expr) *limitgiftLogDo {
	return l.withDO(l.DO.Omit(cols...))
}

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

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

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

func (l limitgiftLogDo) Group(cols ...field.Expr) *limitgiftLogDo {
	return l.withDO(l.DO.Group(cols...))
}

func (l limitgiftLogDo) Having(conds ...gen.Condition) *limitgiftLogDo {
	return l.withDO(l.DO.Having(conds...))
}

func (l limitgiftLogDo) Limit(limit int) *limitgiftLogDo {
	return l.withDO(l.DO.Limit(limit))
}

func (l limitgiftLogDo) Offset(offset int) *limitgiftLogDo {
	return l.withDO(l.DO.Offset(offset))
}

func (l limitgiftLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *limitgiftLogDo {
	return l.withDO(l.DO.Scopes(funcs...))
}

func (l limitgiftLogDo) Unscoped() *limitgiftLogDo {
	return l.withDO(l.DO.Unscoped())
}

func (l limitgiftLogDo) Create(values ...*model.LimitgiftLog) error {
	if len(values) == 0 {
		return nil
	}
	return l.DO.Create(values)
}

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

func (l limitgiftLogDo) First() (*model.LimitgiftLog, error) {
	if result, err := l.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.LimitgiftLog), nil
	}
}

func (l limitgiftLogDo) Take() (*model.LimitgiftLog, error) {
	if result, err := l.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.LimitgiftLog), nil
	}
}

func (l limitgiftLogDo) Last() (*model.LimitgiftLog, error) {
	if result, err := l.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.LimitgiftLog), nil
	}
}

func (l limitgiftLogDo) Find() ([]*model.LimitgiftLog, error) {
	result, err := l.DO.Find()
	return result.([]*model.LimitgiftLog), err
}

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

func (l limitgiftLogDo) Attrs(attrs ...field.AssignExpr) *limitgiftLogDo {
	return l.withDO(l.DO.Attrs(attrs...))
}

func (l limitgiftLogDo) Assign(attrs ...field.AssignExpr) *limitgiftLogDo {
	return l.withDO(l.DO.Assign(attrs...))
}

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

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

func (l limitgiftLogDo) FirstOrInit() (*model.LimitgiftLog, error) {
	if result, err := l.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.LimitgiftLog), nil
	}
}

func (l limitgiftLogDo) FirstOrCreate() (*model.LimitgiftLog, error) {
	if result, err := l.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.LimitgiftLog), nil
	}
}

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

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

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

func (l limitgiftLogDo) Scan(result interface{}) (err error) {
	return l.DO.Scan(result)
}

func (l limitgiftLogDo) Delete(models ...*model.LimitgiftLog) (result gen.ResultInfo, err error) {
	return l.DO.Delete(models)
}

func (l *limitgiftLogDo) withDO(do gen.Dao) *limitgiftLogDo {
	l.DO = *do.(*gen.DO)
	return l
}
