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

	_activityDrawEffects.activityDrawEffectsDo.UseDB(db, opts...)
	_activityDrawEffects.activityDrawEffectsDo.UseModel(&model.ActivityDrawEffects{})

	tableName := _activityDrawEffects.activityDrawEffectsDo.TableName()
	_activityDrawEffects.ALL = field.NewAsterisk(tableName)
	_activityDrawEffects.ID = field.NewInt64(tableName, "id")
	_activityDrawEffects.CreatedAt = field.NewTime(tableName, "created_at")
	_activityDrawEffects.DrawLogID = field.NewInt64(tableName, "draw_log_id")
	_activityDrawEffects.UserID = field.NewInt64(tableName, "user_id")
	_activityDrawEffects.UserItemCardID = field.NewInt64(tableName, "user_item_card_id")
	_activityDrawEffects.SystemItemCardID = field.NewInt64(tableName, "system_item_card_id")
	_activityDrawEffects.Applied = field.NewInt32(tableName, "applied")
	_activityDrawEffects.CardType = field.NewInt32(tableName, "card_type")
	_activityDrawEffects.EffectType = field.NewInt32(tableName, "effect_type")
	_activityDrawEffects.RewardMultiplierX1000 = field.NewInt32(tableName, "reward_multiplier_x1000")
	_activityDrawEffects.ProbabilityDeltaX1000 = field.NewInt32(tableName, "probability_delta_x1000")
	_activityDrawEffects.ScopeType = field.NewInt32(tableName, "scope_type")
	_activityDrawEffects.ActivityCategoryID = field.NewInt64(tableName, "activity_category_id")
	_activityDrawEffects.ActivityID = field.NewInt64(tableName, "activity_id")
	_activityDrawEffects.IssueID = field.NewInt64(tableName, "issue_id")
	_activityDrawEffects.Remark = field.NewString(tableName, "remark")

	_activityDrawEffects.fillFieldMap()

	return _activityDrawEffects
}

// activityDrawEffects 抽奖效果日志
type activityDrawEffects struct {
	activityDrawEffectsDo

	ALL                   field.Asterisk
	ID                    field.Int64  // 主键ID
	CreatedAt             field.Time   // 创建时间
	DrawLogID             field.Int64  // 抽奖日志ID（activity_draw_logs.id）
	UserID                field.Int64  // 用户ID（users.id）
	UserItemCardID        field.Int64  // 用户卡实例ID（user_item_cards.id）
	SystemItemCardID      field.Int64  // 卡模板ID（system_item_cards.id）
	Applied               field.Int32  // 是否生效：0否 1是
	CardType              field.Int32  // 卡类型快照
	EffectType            field.Int32  // 效果类型快照
	RewardMultiplierX1000 field.Int32  // 奖励倍数（千分比）
	ProbabilityDeltaX1000 field.Int32  // 概率相对增益（千分比）
	ScopeType             field.Int32  // 适用范围快照
	ActivityCategoryID    field.Int64  // 范围快照-活动分类ID
	ActivityID            field.Int64  // 范围快照-活动ID
	IssueID               field.Int64  // 范围快照-期ID
	Remark                field.String // 备注

	fieldMap map[string]field.Expr
}

func (a activityDrawEffects) Table(newTableName string) *activityDrawEffects {
	a.activityDrawEffectsDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

func (a activityDrawEffects) As(alias string) *activityDrawEffects {
	a.activityDrawEffectsDo.DO = *(a.activityDrawEffectsDo.As(alias).(*gen.DO))
	return a.updateTableName(alias)
}

func (a *activityDrawEffects) updateTableName(table string) *activityDrawEffects {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt64(table, "id")
	a.CreatedAt = field.NewTime(table, "created_at")
	a.DrawLogID = field.NewInt64(table, "draw_log_id")
	a.UserID = field.NewInt64(table, "user_id")
	a.UserItemCardID = field.NewInt64(table, "user_item_card_id")
	a.SystemItemCardID = field.NewInt64(table, "system_item_card_id")
	a.Applied = field.NewInt32(table, "applied")
	a.CardType = field.NewInt32(table, "card_type")
	a.EffectType = field.NewInt32(table, "effect_type")
	a.RewardMultiplierX1000 = field.NewInt32(table, "reward_multiplier_x1000")
	a.ProbabilityDeltaX1000 = field.NewInt32(table, "probability_delta_x1000")
	a.ScopeType = field.NewInt32(table, "scope_type")
	a.ActivityCategoryID = field.NewInt64(table, "activity_category_id")
	a.ActivityID = field.NewInt64(table, "activity_id")
	a.IssueID = field.NewInt64(table, "issue_id")
	a.Remark = field.NewString(table, "remark")

	a.fillFieldMap()

	return a
}

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

func (a *activityDrawEffects) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 16)
	a.fieldMap["id"] = a.ID
	a.fieldMap["created_at"] = a.CreatedAt
	a.fieldMap["draw_log_id"] = a.DrawLogID
	a.fieldMap["user_id"] = a.UserID
	a.fieldMap["user_item_card_id"] = a.UserItemCardID
	a.fieldMap["system_item_card_id"] = a.SystemItemCardID
	a.fieldMap["applied"] = a.Applied
	a.fieldMap["card_type"] = a.CardType
	a.fieldMap["effect_type"] = a.EffectType
	a.fieldMap["reward_multiplier_x1000"] = a.RewardMultiplierX1000
	a.fieldMap["probability_delta_x1000"] = a.ProbabilityDeltaX1000
	a.fieldMap["scope_type"] = a.ScopeType
	a.fieldMap["activity_category_id"] = a.ActivityCategoryID
	a.fieldMap["activity_id"] = a.ActivityID
	a.fieldMap["issue_id"] = a.IssueID
	a.fieldMap["remark"] = a.Remark
}

func (a activityDrawEffects) clone(db *gorm.DB) activityDrawEffects {
	a.activityDrawEffectsDo.ReplaceConnPool(db.Statement.ConnPool)
	return a
}

func (a activityDrawEffects) replaceDB(db *gorm.DB) activityDrawEffects {
	a.activityDrawEffectsDo.ReplaceDB(db)
	return a
}

type activityDrawEffectsDo struct{ gen.DO }

func (a activityDrawEffectsDo) Debug() *activityDrawEffectsDo {
	return a.withDO(a.DO.Debug())
}

func (a activityDrawEffectsDo) WithContext(ctx context.Context) *activityDrawEffectsDo {
	return a.withDO(a.DO.WithContext(ctx))
}

func (a activityDrawEffectsDo) ReadDB() *activityDrawEffectsDo {
	return a.Clauses(dbresolver.Read)
}

func (a activityDrawEffectsDo) WriteDB() *activityDrawEffectsDo {
	return a.Clauses(dbresolver.Write)
}

func (a activityDrawEffectsDo) Session(config *gorm.Session) *activityDrawEffectsDo {
	return a.withDO(a.DO.Session(config))
}

func (a activityDrawEffectsDo) Clauses(conds ...clause.Expression) *activityDrawEffectsDo {
	return a.withDO(a.DO.Clauses(conds...))
}

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

func (a activityDrawEffectsDo) Not(conds ...gen.Condition) *activityDrawEffectsDo {
	return a.withDO(a.DO.Not(conds...))
}

func (a activityDrawEffectsDo) Or(conds ...gen.Condition) *activityDrawEffectsDo {
	return a.withDO(a.DO.Or(conds...))
}

func (a activityDrawEffectsDo) Select(conds ...field.Expr) *activityDrawEffectsDo {
	return a.withDO(a.DO.Select(conds...))
}

func (a activityDrawEffectsDo) Where(conds ...gen.Condition) *activityDrawEffectsDo {
	return a.withDO(a.DO.Where(conds...))
}

func (a activityDrawEffectsDo) Order(conds ...field.Expr) *activityDrawEffectsDo {
	return a.withDO(a.DO.Order(conds...))
}

func (a activityDrawEffectsDo) Distinct(cols ...field.Expr) *activityDrawEffectsDo {
	return a.withDO(a.DO.Distinct(cols...))
}

func (a activityDrawEffectsDo) Omit(cols ...field.Expr) *activityDrawEffectsDo {
	return a.withDO(a.DO.Omit(cols...))
}

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

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

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

func (a activityDrawEffectsDo) Group(cols ...field.Expr) *activityDrawEffectsDo {
	return a.withDO(a.DO.Group(cols...))
}

func (a activityDrawEffectsDo) Having(conds ...gen.Condition) *activityDrawEffectsDo {
	return a.withDO(a.DO.Having(conds...))
}

func (a activityDrawEffectsDo) Limit(limit int) *activityDrawEffectsDo {
	return a.withDO(a.DO.Limit(limit))
}

func (a activityDrawEffectsDo) Offset(offset int) *activityDrawEffectsDo {
	return a.withDO(a.DO.Offset(offset))
}

func (a activityDrawEffectsDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *activityDrawEffectsDo {
	return a.withDO(a.DO.Scopes(funcs...))
}

func (a activityDrawEffectsDo) Unscoped() *activityDrawEffectsDo {
	return a.withDO(a.DO.Unscoped())
}

func (a activityDrawEffectsDo) Create(values ...*model.ActivityDrawEffects) error {
	if len(values) == 0 {
		return nil
	}
	return a.DO.Create(values)
}

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

func (a activityDrawEffectsDo) First() (*model.ActivityDrawEffects, error) {
	if result, err := a.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityDrawEffects), nil
	}
}

func (a activityDrawEffectsDo) Take() (*model.ActivityDrawEffects, error) {
	if result, err := a.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityDrawEffects), nil
	}
}

func (a activityDrawEffectsDo) Last() (*model.ActivityDrawEffects, error) {
	if result, err := a.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityDrawEffects), nil
	}
}

func (a activityDrawEffectsDo) Find() ([]*model.ActivityDrawEffects, error) {
	result, err := a.DO.Find()
	return result.([]*model.ActivityDrawEffects), err
}

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

func (a activityDrawEffectsDo) Attrs(attrs ...field.AssignExpr) *activityDrawEffectsDo {
	return a.withDO(a.DO.Attrs(attrs...))
}

func (a activityDrawEffectsDo) Assign(attrs ...field.AssignExpr) *activityDrawEffectsDo {
	return a.withDO(a.DO.Assign(attrs...))
}

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

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

func (a activityDrawEffectsDo) FirstOrInit() (*model.ActivityDrawEffects, error) {
	if result, err := a.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityDrawEffects), nil
	}
}

func (a activityDrawEffectsDo) FirstOrCreate() (*model.ActivityDrawEffects, error) {
	if result, err := a.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ActivityDrawEffects), nil
	}
}

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

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

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

func (a activityDrawEffectsDo) Scan(result interface{}) (err error) {
	return a.DO.Scan(result)
}

func (a activityDrawEffectsDo) Delete(models ...*model.ActivityDrawEffects) (result gen.ResultInfo, err error) {
	return a.DO.Delete(models)
}

func (a *activityDrawEffectsDo) withDO(do gen.Dao) *activityDrawEffectsDo {
	a.DO = *do.(*gen.DO)
	return a
}
