package cumulativerecharge

const (
	TierStatusActive   = "active"
	TierStatusInactive = "inactive"

	GrantStatusPending = "pending"
	GrantStatusGranted = "granted"
	GrantStatusFailed  = "failed"

	ReasonEligible          = "eligible"
	ReasonNotConfigured     = "not_configured"
	ReasonDisabled          = "disabled"
	ReasonNoQualifyingValue = "no_qualifying_value"
	ReasonAlreadyConsumed   = "already_consumed"
	ReasonNoTierMatched     = "no_tier_matched"
	ReasonPendingReward     = "pending_reward"

	RechargeEventWalletRecorded = "WalletRechargeRecorded"
	RechargeTypeCoinSeller      = "coin_seller_transfer"
)

// Tier 是累充奖励的 USD 档位，金额统一用美分保存，避免后台小数金额和发放判断出现精度漂移。
type Tier struct {
	TierID            int64
	TierCode          string
	TierName          string
	ThresholdUSDMinor int64
	ResourceGroupID   int64
	Status            string
	SortOrder         int32
	CreatedAtMS       int64
	UpdatedAtMS       int64
}

// Config 是当前 App 的累充奖励配置；activity-service 保存档位快照并负责后续充值事件判定。
type Config struct {
	AppCode          string
	Enabled          bool
	Tiers            []Tier
	UpdatedByAdminID int64
	CreatedAtMS      int64
	UpdatedAtMS      int64
}

// Progress 是用户在一个 UTC 自然周内的累充累计投影。
type Progress struct {
	AppCode            string
	CycleKey           string
	UserID             int64
	TotalUSDMinor      int64
	TotalCoinAmount    int64
	FirstRechargedAtMS int64
	LastRechargedAtMS  int64
	UpdatedAtMS        int64
}

// Grant 是用户命中某个累充档位后的资源组发放事实；event 字段用于 MQ 重试复用原命令。
type Grant struct {
	GrantID            string
	AppCode            string
	CycleKey           string
	UserID             int64
	EventID            string
	TransactionID      string
	CommandID          string
	TierID             int64
	TierCode           string
	ThresholdUSDMinor  int64
	ResourceGroupID    int64
	ReachedUSDMinor    int64
	QualifyingUSDMinor int64
	RechargeCoinAmount int64
	RechargeType       string
	Status             string
	WalletCommandID    string
	WalletGrantID      string
	FailureReason      string
	GrantedAtMS        int64
	CreatedAtMS        int64
	UpdatedAtMS        int64
}

// RechargeEvent 是 wallet_outbox 里进入累充奖励的成功充值事实。
type RechargeEvent struct {
	AppCode            string
	EventID            string
	EventType          string
	TransactionID      string
	CommandID          string
	UserID             int64
	RechargeCoinAmount int64
	RechargeSequence   int64
	RechargeType       string
	QualifyingUSDMinor int64
	PayloadJSON        string
	OccurredAtMS       int64
}

// Cycle 表达 UTC 自然周周期边界。
type Cycle struct {
	Key     string
	StartMS int64
	EndMS   int64
}

// StatusResult 是 App H5 页面读取的完整累充状态。
type StatusResult struct {
	Config       Config
	Progress     Progress
	Grants       []Grant
	Cycle        Cycle
	ServerTimeMS int64
}

// PrepareResult 表达一次充值事实在 MySQL 事务内是否产生了需要执行的发放命令。
type PrepareResult struct {
	Grants   []Grant
	Consumed bool
	Reason   string
}

// GrantQuery 是后台发放记录分页查询条件。
type GrantQuery struct {
	Status   string
	UserID   int64
	CycleKey string
	Page     int32
	PageSize int32
}
