// 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 dao

import (
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"bindbox-game/internal/repository/mysql/model"
)

func newLotteryRefundLogs(db *gorm.DB, opts ...gen.DOOption) lotteryRefundLogs {
	_lotteryRefundLogs := lotteryRefundLogs{}

	_lotteryRefundLogs.lotteryRefundLogsDo.UseDB(db, opts...)
	_lotteryRefundLogs.lotteryRefundLogsDo.UseModel(&model.LotteryRefundLogs{})

	tableName := _lotteryRefundLogs.lotteryRefundLogsDo.TableName()
	_lotteryRefundLogs.ALL = field.NewAsterisk(tableName)
	_lotteryRefundLogs.ID = field.NewInt64(tableName, "id")
	_lotteryRefundLogs.IssueID = field.NewInt64(tableName, "issue_id")
	_lotteryRefundLogs.OrderID = field.NewInt64(tableName, "order_id")
	_lotteryRefundLogs.UserID = field.NewInt64(tableName, "user_id")
	_lotteryRefundLogs.Amount = field.NewInt64(tableName, "amount")
	_lotteryRefundLogs.CouponType = field.NewString(tableName, "coupon_type")
	_lotteryRefundLogs.CouponAmount = field.NewInt64(tableName, "coupon_amount")
	_lotteryRefundLogs.Reason = field.NewString(tableName, "reason")
	_lotteryRefundLogs.Status = field.NewString(tableName, "status")
	_lotteryRefundLogs.CreatedAt = field.NewTime(tableName, "created_at")
	_lotteryRefundLogs.UpdatedAt = field.NewTime(tableName, "updated_at")

	_lotteryRefundLogs.fillFieldMap()

	return _lotteryRefundLogs
}

type lotteryRefundLogs struct {
	lotteryRefundLogsDo

	ALL          field.Asterisk
	ID           field.Int64
	IssueID      field.Int64
	OrderID      field.Int64
	UserID       field.Int64
	Amount       field.Int64
	CouponType   field.String
	CouponAmount field.Int64
	Reason       field.String
	Status       field.String
	CreatedAt    field.Time
	UpdatedAt    field.Time

	fieldMap map[string]field.Expr
}

func (l lotteryRefundLogs) Table(newTableName string) *lotteryRefundLogs {
	l.lotteryRefundLogsDo.UseTable(newTableName)
	return l.updateTableName(newTableName)
}

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

func (l *lotteryRefundLogs) updateTableName(table string) *lotteryRefundLogs {
	l.ALL = field.NewAsterisk(table)
	l.ID = field.NewInt64(table, "id")
	l.IssueID = field.NewInt64(table, "issue_id")
	l.OrderID = field.NewInt64(table, "order_id")
	l.UserID = field.NewInt64(table, "user_id")
	l.Amount = field.NewInt64(table, "amount")
	l.CouponType = field.NewString(table, "coupon_type")
	l.CouponAmount = field.NewInt64(table, "coupon_amount")
	l.Reason = field.NewString(table, "reason")
	l.Status = field.NewString(table, "status")
	l.CreatedAt = field.NewTime(table, "created_at")
	l.UpdatedAt = field.NewTime(table, "updated_at")

	l.fillFieldMap()

	return l
}

func (l *lotteryRefundLogs) 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 *lotteryRefundLogs) fillFieldMap() {
	l.fieldMap = make(map[string]field.Expr, 11)
	l.fieldMap["id"] = l.ID
	l.fieldMap["issue_id"] = l.IssueID
	l.fieldMap["order_id"] = l.OrderID
	l.fieldMap["user_id"] = l.UserID
	l.fieldMap["amount"] = l.Amount
	l.fieldMap["coupon_type"] = l.CouponType
	l.fieldMap["coupon_amount"] = l.CouponAmount
	l.fieldMap["reason"] = l.Reason
	l.fieldMap["status"] = l.Status
	l.fieldMap["created_at"] = l.CreatedAt
	l.fieldMap["updated_at"] = l.UpdatedAt
}

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

func (l lotteryRefundLogs) replaceDB(db *gorm.DB) lotteryRefundLogs {
	l.lotteryRefundLogsDo.ReplaceDB(db)
	return l
}

type lotteryRefundLogsDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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