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

	_activities.activitiesDo.UseDB(db, opts...)
	_activities.activitiesDo.UseModel(&model.Activities{})

	tableName := _activities.activitiesDo.TableName()
	_activities.ALL = field.NewAsterisk(tableName)
	_activities.ID = field.NewInt64(tableName, "id")
	_activities.CreatedAt = field.NewTime(tableName, "created_at")
	_activities.UpdatedAt = field.NewTime(tableName, "updated_at")
	_activities.Name = field.NewString(tableName, "name")
	_activities.Banner = field.NewString(tableName, "banner")
	_activities.ActivityCategoryID = field.NewInt64(tableName, "activity_category_id")
	_activities.Status = field.NewInt32(tableName, "status")
	_activities.PriceDraw = field.NewInt64(tableName, "price_draw")
	_activities.IsBoss = field.NewInt32(tableName, "is_boss")
	_activities.AllowItemCards = field.NewBool(tableName, "allow_item_cards")
	_activities.AllowCoupons = field.NewBool(tableName, "allow_coupons")
	_activities.StartTime = field.NewTime(tableName, "start_time")
	_activities.EndTime = field.NewTime(tableName, "end_time")
	_activities.DrawMode = field.NewString(tableName, "draw_mode")
	_activities.PlayType = field.NewString(tableName, "play_type")
	_activities.MinParticipants = field.NewInt64(tableName, "min_participants")
	_activities.IntervalMinutes = field.NewInt64(tableName, "interval_minutes")
	_activities.ScheduledTime = field.NewTime(tableName, "scheduled_time")
	_activities.LastSettledAt = field.NewTime(tableName, "last_settled_at")
	_activities.RefundCouponID = field.NewInt64(tableName, "refund_coupon_id")
	_activities.DeletedAt = field.NewField(tableName, "deleted_at")
	_activities.Image = field.NewString(tableName, "image")
	_activities.CommitmentAlgo = field.NewString(tableName, "commitment_algo")
	_activities.CommitmentSeedMaster = field.NewBytes(tableName, "commitment_seed_master")
	_activities.CommitmentSeedHash = field.NewBytes(tableName, "commitment_seed_hash")
	_activities.CommitmentStateVersion = field.NewInt32(tableName, "commitment_state_version")
	_activities.CommitmentItemsRoot = field.NewBytes(tableName, "commitment_items_root")
	_activities.GameplayIntro = field.NewString(tableName, "gameplay_intro")
	_activities.DailySeed = field.NewString(tableName, "daily_seed")
	_activities.DailySeedDate = field.NewString(tableName, "daily_seed_date")
	_activities.LastDailySeed = field.NewString(tableName, "last_daily_seed")
	_activities.LastDailySeedDate = field.NewString(tableName, "last_daily_seed_date")

	_activities.fillFieldMap()

	return _activities
}

// activities 活动
type activities struct {
	activitiesDo

	ALL                    field.Asterisk
	ID                     field.Int64  // 主键ID
	CreatedAt              field.Time   // 创建时间
	UpdatedAt              field.Time   // 更新时间
	Name                   field.String // 活动名称
	Banner                 field.String // 活动横幅/海报URL
	ActivityCategoryID     field.Int64  // 活动所属分类ID（activity_categories.id，可空）
	Status                 field.Int32  // 状态：1进行中 2下线
	PriceDraw              field.Int64  // 活动门票价格
	IsBoss                 field.Int32  // Boss: 1 是 0 不是
	AllowItemCards         field.Bool   // 是否允许使用道具卡
	AllowCoupons           field.Bool   // 是否允许使用优惠券
	StartTime              field.Time   // 开始时间
	EndTime                field.Time   // 结束时间
	DrawMode               field.String
	PlayType               field.String
	MinParticipants        field.Int64
	IntervalMinutes        field.Int64
	ScheduledTime          field.Time
	LastSettledAt          field.Time
	RefundCouponID         field.Int64
	DeletedAt              field.Field
	Image                  field.String // 活动图片地址
	CommitmentAlgo         field.String
	CommitmentSeedMaster   field.Bytes
	CommitmentSeedHash     field.Bytes
	CommitmentStateVersion field.Int32
	CommitmentItemsRoot    field.Bytes
	GameplayIntro          field.String // 玩法介绍
	DailySeed              field.String
	DailySeedDate          field.String // 种子日期(YYYY-MM-DD)
	LastDailySeed          field.String // 昨日种子
	LastDailySeedDate      field.String // 昨日种子日期

	fieldMap map[string]field.Expr
}

func (a activities) Table(newTableName string) *activities {
	a.activitiesDo.UseTable(newTableName)
	return a.updateTableName(newTableName)
}

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

func (a *activities) updateTableName(table string) *activities {
	a.ALL = field.NewAsterisk(table)
	a.ID = field.NewInt64(table, "id")
	a.CreatedAt = field.NewTime(table, "created_at")
	a.UpdatedAt = field.NewTime(table, "updated_at")
	a.Name = field.NewString(table, "name")
	a.Banner = field.NewString(table, "banner")
	a.ActivityCategoryID = field.NewInt64(table, "activity_category_id")
	a.Status = field.NewInt32(table, "status")
	a.PriceDraw = field.NewInt64(table, "price_draw")
	a.IsBoss = field.NewInt32(table, "is_boss")
	a.AllowItemCards = field.NewBool(table, "allow_item_cards")
	a.AllowCoupons = field.NewBool(table, "allow_coupons")
	a.StartTime = field.NewTime(table, "start_time")
	a.EndTime = field.NewTime(table, "end_time")
	a.DrawMode = field.NewString(table, "draw_mode")
	a.PlayType = field.NewString(table, "play_type")
	a.MinParticipants = field.NewInt64(table, "min_participants")
	a.IntervalMinutes = field.NewInt64(table, "interval_minutes")
	a.ScheduledTime = field.NewTime(table, "scheduled_time")
	a.LastSettledAt = field.NewTime(table, "last_settled_at")
	a.RefundCouponID = field.NewInt64(table, "refund_coupon_id")
	a.DeletedAt = field.NewField(table, "deleted_at")
	a.Image = field.NewString(table, "image")
	a.CommitmentAlgo = field.NewString(table, "commitment_algo")
	a.CommitmentSeedMaster = field.NewBytes(table, "commitment_seed_master")
	a.CommitmentSeedHash = field.NewBytes(table, "commitment_seed_hash")
	a.CommitmentStateVersion = field.NewInt32(table, "commitment_state_version")
	a.CommitmentItemsRoot = field.NewBytes(table, "commitment_items_root")
	a.GameplayIntro = field.NewString(table, "gameplay_intro")
	a.DailySeed = field.NewString(table, "daily_seed")
	a.DailySeedDate = field.NewString(table, "daily_seed_date")
	a.LastDailySeed = field.NewString(table, "last_daily_seed")
	a.LastDailySeedDate = field.NewString(table, "last_daily_seed_date")

	a.fillFieldMap()

	return a
}

func (a *activities) 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 *activities) fillFieldMap() {
	a.fieldMap = make(map[string]field.Expr, 32)
	a.fieldMap["id"] = a.ID
	a.fieldMap["created_at"] = a.CreatedAt
	a.fieldMap["updated_at"] = a.UpdatedAt
	a.fieldMap["name"] = a.Name
	a.fieldMap["banner"] = a.Banner
	a.fieldMap["activity_category_id"] = a.ActivityCategoryID
	a.fieldMap["status"] = a.Status
	a.fieldMap["price_draw"] = a.PriceDraw
	a.fieldMap["is_boss"] = a.IsBoss
	a.fieldMap["allow_item_cards"] = a.AllowItemCards
	a.fieldMap["allow_coupons"] = a.AllowCoupons
	a.fieldMap["start_time"] = a.StartTime
	a.fieldMap["end_time"] = a.EndTime
	a.fieldMap["draw_mode"] = a.DrawMode
	a.fieldMap["play_type"] = a.PlayType
	a.fieldMap["min_participants"] = a.MinParticipants
	a.fieldMap["interval_minutes"] = a.IntervalMinutes
	a.fieldMap["scheduled_time"] = a.ScheduledTime
	a.fieldMap["last_settled_at"] = a.LastSettledAt
	a.fieldMap["refund_coupon_id"] = a.RefundCouponID
	a.fieldMap["deleted_at"] = a.DeletedAt
	a.fieldMap["image"] = a.Image
	a.fieldMap["commitment_algo"] = a.CommitmentAlgo
	a.fieldMap["commitment_seed_master"] = a.CommitmentSeedMaster
	a.fieldMap["commitment_seed_hash"] = a.CommitmentSeedHash
	a.fieldMap["commitment_state_version"] = a.CommitmentStateVersion
	a.fieldMap["commitment_items_root"] = a.CommitmentItemsRoot
	a.fieldMap["gameplay_intro"] = a.GameplayIntro
	a.fieldMap["daily_seed"] = a.DailySeed
	a.fieldMap["daily_seed_date"] = a.DailySeedDate
	a.fieldMap["last_daily_seed"] = a.LastDailySeed
	a.fieldMap["last_daily_seed_date"] = a.LastDailySeedDate
}

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

func (a activities) replaceDB(db *gorm.DB) activities {
	a.activitiesDo.ReplaceDB(db)
	return a
}

type activitiesDo struct{ gen.DO }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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