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

	_issuePositionClaims.issuePositionClaimsDo.UseDB(db, opts...)
	_issuePositionClaims.issuePositionClaimsDo.UseModel(&model.IssuePositionClaims{})

	tableName := _issuePositionClaims.issuePositionClaimsDo.TableName()
	_issuePositionClaims.ALL = field.NewAsterisk(tableName)
	_issuePositionClaims.ID = field.NewInt64(tableName, "id")
	_issuePositionClaims.CreatedAt = field.NewTime(tableName, "created_at")
	_issuePositionClaims.IssueID = field.NewInt64(tableName, "issue_id")
	_issuePositionClaims.SlotIndex = field.NewInt64(tableName, "slot_index")
	_issuePositionClaims.UserID = field.NewInt64(tableName, "user_id")
	_issuePositionClaims.OrderID = field.NewInt64(tableName, "order_id")

	_issuePositionClaims.fillFieldMap()

	return _issuePositionClaims
}

type issuePositionClaims struct {
	issuePositionClaimsDo

	ALL       field.Asterisk
	ID        field.Int64
	CreatedAt field.Time
	IssueID   field.Int64
	SlotIndex field.Int64
	UserID    field.Int64
	OrderID   field.Int64

	fieldMap map[string]field.Expr
}

func (i issuePositionClaims) Table(newTableName string) *issuePositionClaims {
	i.issuePositionClaimsDo.UseTable(newTableName)
	return i.updateTableName(newTableName)
}

func (i issuePositionClaims) As(alias string) *issuePositionClaims {
	i.issuePositionClaimsDo.DO = *(i.issuePositionClaimsDo.As(alias).(*gen.DO))
	return i.updateTableName(alias)
}

func (i *issuePositionClaims) updateTableName(table string) *issuePositionClaims {
	i.ALL = field.NewAsterisk(table)
	i.ID = field.NewInt64(table, "id")
	i.CreatedAt = field.NewTime(table, "created_at")
	i.IssueID = field.NewInt64(table, "issue_id")
	i.SlotIndex = field.NewInt64(table, "slot_index")
	i.UserID = field.NewInt64(table, "user_id")
	i.OrderID = field.NewInt64(table, "order_id")

	i.fillFieldMap()

	return i
}

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

func (i *issuePositionClaims) fillFieldMap() {
	i.fieldMap = make(map[string]field.Expr, 6)
	i.fieldMap["id"] = i.ID
	i.fieldMap["created_at"] = i.CreatedAt
	i.fieldMap["issue_id"] = i.IssueID
	i.fieldMap["slot_index"] = i.SlotIndex
	i.fieldMap["user_id"] = i.UserID
	i.fieldMap["order_id"] = i.OrderID
}

func (i issuePositionClaims) clone(db *gorm.DB) issuePositionClaims {
	i.issuePositionClaimsDo.ReplaceConnPool(db.Statement.ConnPool)
	return i
}

func (i issuePositionClaims) replaceDB(db *gorm.DB) issuePositionClaims {
	i.issuePositionClaimsDo.ReplaceDB(db)
	return i
}

type issuePositionClaimsDo struct{ gen.DO }

func (i issuePositionClaimsDo) Debug() *issuePositionClaimsDo {
	return i.withDO(i.DO.Debug())
}

func (i issuePositionClaimsDo) WithContext(ctx context.Context) *issuePositionClaimsDo {
	return i.withDO(i.DO.WithContext(ctx))
}

func (i issuePositionClaimsDo) ReadDB() *issuePositionClaimsDo {
	return i.Clauses(dbresolver.Read)
}

func (i issuePositionClaimsDo) WriteDB() *issuePositionClaimsDo {
	return i.Clauses(dbresolver.Write)
}

func (i issuePositionClaimsDo) Session(config *gorm.Session) *issuePositionClaimsDo {
	return i.withDO(i.DO.Session(config))
}

func (i issuePositionClaimsDo) Clauses(conds ...clause.Expression) *issuePositionClaimsDo {
	return i.withDO(i.DO.Clauses(conds...))
}

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

func (i issuePositionClaimsDo) Not(conds ...gen.Condition) *issuePositionClaimsDo {
	return i.withDO(i.DO.Not(conds...))
}

func (i issuePositionClaimsDo) Or(conds ...gen.Condition) *issuePositionClaimsDo {
	return i.withDO(i.DO.Or(conds...))
}

func (i issuePositionClaimsDo) Select(conds ...field.Expr) *issuePositionClaimsDo {
	return i.withDO(i.DO.Select(conds...))
}

func (i issuePositionClaimsDo) Where(conds ...gen.Condition) *issuePositionClaimsDo {
	return i.withDO(i.DO.Where(conds...))
}

func (i issuePositionClaimsDo) Order(conds ...field.Expr) *issuePositionClaimsDo {
	return i.withDO(i.DO.Order(conds...))
}

func (i issuePositionClaimsDo) Distinct(cols ...field.Expr) *issuePositionClaimsDo {
	return i.withDO(i.DO.Distinct(cols...))
}

func (i issuePositionClaimsDo) Omit(cols ...field.Expr) *issuePositionClaimsDo {
	return i.withDO(i.DO.Omit(cols...))
}

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

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

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

func (i issuePositionClaimsDo) Group(cols ...field.Expr) *issuePositionClaimsDo {
	return i.withDO(i.DO.Group(cols...))
}

func (i issuePositionClaimsDo) Having(conds ...gen.Condition) *issuePositionClaimsDo {
	return i.withDO(i.DO.Having(conds...))
}

func (i issuePositionClaimsDo) Limit(limit int) *issuePositionClaimsDo {
	return i.withDO(i.DO.Limit(limit))
}

func (i issuePositionClaimsDo) Offset(offset int) *issuePositionClaimsDo {
	return i.withDO(i.DO.Offset(offset))
}

func (i issuePositionClaimsDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *issuePositionClaimsDo {
	return i.withDO(i.DO.Scopes(funcs...))
}

func (i issuePositionClaimsDo) Unscoped() *issuePositionClaimsDo {
	return i.withDO(i.DO.Unscoped())
}

func (i issuePositionClaimsDo) Create(values ...*model.IssuePositionClaims) error {
	if len(values) == 0 {
		return nil
	}
	return i.DO.Create(values)
}

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

func (i issuePositionClaimsDo) First() (*model.IssuePositionClaims, error) {
	if result, err := i.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.IssuePositionClaims), nil
	}
}

func (i issuePositionClaimsDo) Take() (*model.IssuePositionClaims, error) {
	if result, err := i.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.IssuePositionClaims), nil
	}
}

func (i issuePositionClaimsDo) Last() (*model.IssuePositionClaims, error) {
	if result, err := i.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.IssuePositionClaims), nil
	}
}

func (i issuePositionClaimsDo) Find() ([]*model.IssuePositionClaims, error) {
	result, err := i.DO.Find()
	return result.([]*model.IssuePositionClaims), err
}

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

func (i issuePositionClaimsDo) Attrs(attrs ...field.AssignExpr) *issuePositionClaimsDo {
	return i.withDO(i.DO.Attrs(attrs...))
}

func (i issuePositionClaimsDo) Assign(attrs ...field.AssignExpr) *issuePositionClaimsDo {
	return i.withDO(i.DO.Assign(attrs...))
}

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

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

func (i issuePositionClaimsDo) FirstOrInit() (*model.IssuePositionClaims, error) {
	if result, err := i.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.IssuePositionClaims), nil
	}
}

func (i issuePositionClaimsDo) FirstOrCreate() (*model.IssuePositionClaims, error) {
	if result, err := i.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.IssuePositionClaims), nil
	}
}

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

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

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

func (i issuePositionClaimsDo) Scan(result interface{}) (err error) {
	return i.DO.Scan(result)
}

func (i issuePositionClaimsDo) Delete(models ...*model.IssuePositionClaims) (result gen.ResultInfo, err error) {
	return i.DO.Delete(models)
}

func (i *issuePositionClaimsDo) withDO(do gen.Dao) *issuePositionClaimsDo {
	i.DO = *do.(*gen.DO)
	return i
}
