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

	_userInventoryTransfers.userInventoryTransfersDo.UseDB(db, opts...)
	_userInventoryTransfers.userInventoryTransfersDo.UseModel(&model.UserInventoryTransfers{})

	tableName := _userInventoryTransfers.userInventoryTransfersDo.TableName()
	_userInventoryTransfers.ALL = field.NewAsterisk(tableName)
	_userInventoryTransfers.ID = field.NewInt64(tableName, "id")
	_userInventoryTransfers.CreatedAt = field.NewTime(tableName, "created_at")
	_userInventoryTransfers.InventoryID = field.NewInt64(tableName, "inventory_id")
	_userInventoryTransfers.FromUserID = field.NewInt64(tableName, "from_user_id")
	_userInventoryTransfers.ToUserID = field.NewInt64(tableName, "to_user_id")
	_userInventoryTransfers.Remark = field.NewString(tableName, "remark")

	_userInventoryTransfers.fillFieldMap()

	return _userInventoryTransfers
}

// userInventoryTransfers 资产转赠流水
type userInventoryTransfers struct {
	userInventoryTransfersDo

	ALL         field.Asterisk
	ID          field.Int64  // 主键ID
	CreatedAt   field.Time   // 创建时间
	InventoryID field.Int64  // 资产ID（user_inventory.id）
	FromUserID  field.Int64  // 转出用户ID
	ToUserID    field.Int64  // 转入用户ID
	Remark      field.String // 备注

	fieldMap map[string]field.Expr
}

func (u userInventoryTransfers) Table(newTableName string) *userInventoryTransfers {
	u.userInventoryTransfersDo.UseTable(newTableName)
	return u.updateTableName(newTableName)
}

func (u userInventoryTransfers) As(alias string) *userInventoryTransfers {
	u.userInventoryTransfersDo.DO = *(u.userInventoryTransfersDo.As(alias).(*gen.DO))
	return u.updateTableName(alias)
}

func (u *userInventoryTransfers) updateTableName(table string) *userInventoryTransfers {
	u.ALL = field.NewAsterisk(table)
	u.ID = field.NewInt64(table, "id")
	u.CreatedAt = field.NewTime(table, "created_at")
	u.InventoryID = field.NewInt64(table, "inventory_id")
	u.FromUserID = field.NewInt64(table, "from_user_id")
	u.ToUserID = field.NewInt64(table, "to_user_id")
	u.Remark = field.NewString(table, "remark")

	u.fillFieldMap()

	return u
}

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

func (u *userInventoryTransfers) fillFieldMap() {
	u.fieldMap = make(map[string]field.Expr, 6)
	u.fieldMap["id"] = u.ID
	u.fieldMap["created_at"] = u.CreatedAt
	u.fieldMap["inventory_id"] = u.InventoryID
	u.fieldMap["from_user_id"] = u.FromUserID
	u.fieldMap["to_user_id"] = u.ToUserID
	u.fieldMap["remark"] = u.Remark
}

func (u userInventoryTransfers) clone(db *gorm.DB) userInventoryTransfers {
	u.userInventoryTransfersDo.ReplaceConnPool(db.Statement.ConnPool)
	return u
}

func (u userInventoryTransfers) replaceDB(db *gorm.DB) userInventoryTransfers {
	u.userInventoryTransfersDo.ReplaceDB(db)
	return u
}

type userInventoryTransfersDo struct{ gen.DO }

func (u userInventoryTransfersDo) Debug() *userInventoryTransfersDo {
	return u.withDO(u.DO.Debug())
}

func (u userInventoryTransfersDo) WithContext(ctx context.Context) *userInventoryTransfersDo {
	return u.withDO(u.DO.WithContext(ctx))
}

func (u userInventoryTransfersDo) ReadDB() *userInventoryTransfersDo {
	return u.Clauses(dbresolver.Read)
}

func (u userInventoryTransfersDo) WriteDB() *userInventoryTransfersDo {
	return u.Clauses(dbresolver.Write)
}

func (u userInventoryTransfersDo) Session(config *gorm.Session) *userInventoryTransfersDo {
	return u.withDO(u.DO.Session(config))
}

func (u userInventoryTransfersDo) Clauses(conds ...clause.Expression) *userInventoryTransfersDo {
	return u.withDO(u.DO.Clauses(conds...))
}

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

func (u userInventoryTransfersDo) Not(conds ...gen.Condition) *userInventoryTransfersDo {
	return u.withDO(u.DO.Not(conds...))
}

func (u userInventoryTransfersDo) Or(conds ...gen.Condition) *userInventoryTransfersDo {
	return u.withDO(u.DO.Or(conds...))
}

func (u userInventoryTransfersDo) Select(conds ...field.Expr) *userInventoryTransfersDo {
	return u.withDO(u.DO.Select(conds...))
}

func (u userInventoryTransfersDo) Where(conds ...gen.Condition) *userInventoryTransfersDo {
	return u.withDO(u.DO.Where(conds...))
}

func (u userInventoryTransfersDo) Order(conds ...field.Expr) *userInventoryTransfersDo {
	return u.withDO(u.DO.Order(conds...))
}

func (u userInventoryTransfersDo) Distinct(cols ...field.Expr) *userInventoryTransfersDo {
	return u.withDO(u.DO.Distinct(cols...))
}

func (u userInventoryTransfersDo) Omit(cols ...field.Expr) *userInventoryTransfersDo {
	return u.withDO(u.DO.Omit(cols...))
}

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

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

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

func (u userInventoryTransfersDo) Group(cols ...field.Expr) *userInventoryTransfersDo {
	return u.withDO(u.DO.Group(cols...))
}

func (u userInventoryTransfersDo) Having(conds ...gen.Condition) *userInventoryTransfersDo {
	return u.withDO(u.DO.Having(conds...))
}

func (u userInventoryTransfersDo) Limit(limit int) *userInventoryTransfersDo {
	return u.withDO(u.DO.Limit(limit))
}

func (u userInventoryTransfersDo) Offset(offset int) *userInventoryTransfersDo {
	return u.withDO(u.DO.Offset(offset))
}

func (u userInventoryTransfersDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *userInventoryTransfersDo {
	return u.withDO(u.DO.Scopes(funcs...))
}

func (u userInventoryTransfersDo) Unscoped() *userInventoryTransfersDo {
	return u.withDO(u.DO.Unscoped())
}

func (u userInventoryTransfersDo) Create(values ...*model.UserInventoryTransfers) error {
	if len(values) == 0 {
		return nil
	}
	return u.DO.Create(values)
}

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

func (u userInventoryTransfersDo) First() (*model.UserInventoryTransfers, error) {
	if result, err := u.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.UserInventoryTransfers), nil
	}
}

func (u userInventoryTransfersDo) Take() (*model.UserInventoryTransfers, error) {
	if result, err := u.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.UserInventoryTransfers), nil
	}
}

func (u userInventoryTransfersDo) Last() (*model.UserInventoryTransfers, error) {
	if result, err := u.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.UserInventoryTransfers), nil
	}
}

func (u userInventoryTransfersDo) Find() ([]*model.UserInventoryTransfers, error) {
	result, err := u.DO.Find()
	return result.([]*model.UserInventoryTransfers), err
}

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

func (u userInventoryTransfersDo) Attrs(attrs ...field.AssignExpr) *userInventoryTransfersDo {
	return u.withDO(u.DO.Attrs(attrs...))
}

func (u userInventoryTransfersDo) Assign(attrs ...field.AssignExpr) *userInventoryTransfersDo {
	return u.withDO(u.DO.Assign(attrs...))
}

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

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

func (u userInventoryTransfersDo) FirstOrInit() (*model.UserInventoryTransfers, error) {
	if result, err := u.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.UserInventoryTransfers), nil
	}
}

func (u userInventoryTransfersDo) FirstOrCreate() (*model.UserInventoryTransfers, error) {
	if result, err := u.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.UserInventoryTransfers), nil
	}
}

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

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

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

func (u userInventoryTransfersDo) Scan(result interface{}) (err error) {
	return u.DO.Scan(result)
}

func (u userInventoryTransfersDo) Delete(models ...*model.UserInventoryTransfers) (result gen.ResultInfo, err error) {
	return u.DO.Delete(models)
}

func (u *userInventoryTransfersDo) withDO(do gen.Dao) *userInventoryTransfersDo {
	u.DO = *do.(*gen.DO)
	return u
}
