package wheel

const (
	StatusDraft   = "draft"
	StatusActive  = "active"
	StatusPending = "pending"
	StatusGranted = "granted"
	StatusFailed  = "failed"

	RewardTypeCoin  = "coin"
	RewardTypeGift  = "gift"
	RewardTypeProp  = "prop"
	RewardTypeDress = "dress"

	EventTypeWheelRewardSettlement = "WheelRewardSettlement"

	OutboxStatusPending    = "pending"
	OutboxStatusDelivering = "delivering"
	OutboxStatusRetryable  = "retryable"
	OutboxStatusDelivered  = "delivered"
	OutboxStatusFailed     = "failed"
)

// RuleConfig 是转盘配置的不可变版本快照。
// 金币和礼物可以配置 RTP 计值，道具/装扮即使有展示价值也必须在运行态归零。
type RuleConfig struct {
	AppCode               string
	WheelID               string
	RuleVersion           int64
	Enabled               bool
	DrawPriceCoins        int64
	TargetRTPPPM          int64
	PoolRatePPM           int64
	SettlementWindowDraws int64
	InitialPoolCoins      int64
	PoolReserveCoins      int64
	MaxSingleRTPPayout    int64
	EffectiveFromMS       int64
	CreatedByAdminID      int64
	CreatedAtMS           int64
	Tiers                 []Tier
}

// Tier 是一个转盘奖档；RewardType 决定发放 owner 和 RTP 计值口径。
type Tier struct {
	TierID        string
	DisplayName   string
	RewardType    string
	RewardID      string
	RewardCount   int64
	RewardCoins   int64
	RTPValueCoins int64
	WeightPPM     int64
	Enabled       bool
	MetadataJSON  string
}

type DrawCommand struct {
	CommandID       string
	WheelID         string
	UserID          int64
	DeviceID        string
	DrawCount       int32
	CoinSpent       int64
	PaidAtMS        int64
	VisibleRegionID int64
}

type DrawResult struct {
	DrawID              string
	DrawIDs             []string
	CommandID           string
	WheelID             string
	RuleVersion         int64
	SelectedTierID      string
	RewardType          string
	RewardID            string
	RewardCount         int64
	RewardCoins         int64
	RTPValueCoins       int64
	RewardStatus        string
	RTPWindowIndex      int64
	ActualRTPPPM        int64
	CreatedAtMS         int64
	WalletTransactionID string
	CoinBalanceAfter    int64
	MetadataJSON        string
	Rewards             []DrawReward
}

// DrawReward 是批量抽奖响应里的单次命中奖品快照；它只服务展示和协议转换，发奖状态仍以每条 draw record 为准。
type DrawReward struct {
	SelectedTierID string
	RewardType     string
	RewardID       string
	RewardCount    int64
	RewardCoins    int64
	RTPValueCoins  int64
	RewardStatus   string
	MetadataJSON   string
}

type DrawSummary struct {
	WheelID            string
	TotalDraws         int64
	UniqueUsers        int64
	TotalSpentCoins    int64
	TotalRTPValueCoins int64
	ActualRTPPPM       int64
	PendingDraws       int64
	GrantedDraws       int64
	FailedDraws        int64
}

type DrawQuery struct {
	WheelID  string
	UserID   int64
	Status   string
	Page     int32
	PageSize int32
}

// RewardOutboxRecord 是转盘发奖补偿 worker 的持久化工作项。
// Payload 始终保留抽奖事务写入时的不可变奖品快照；补偿时不能回读当前奖档配置，否则运营改配置后会改变历史应发权益。
type RewardOutboxRecord struct {
	AppCode       string
	OutboxID      string
	Payload       []byte
	Status        string
	RetryCount    int
	NextRetryAtMS int64
	LockedBy      string
	LockUntilMS   int64
	LastError     string
	CreatedAtMS   int64
	UpdatedAtMS   int64
}
