package inviteactivity

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

	RewardTypeRecharge      = "recharge"
	RewardTypeValidInvite   = "valid_invite"
	RewardTypeInviteInviter = "invite_inviter"
	RewardTypeInvitee       = "invite_invitee"

	ClaimStatusPending = "pending"
	ClaimStatusGranted = "granted"
	ClaimStatusFailed  = "failed"

	ReasonEligible        = "eligible"
	ReasonAlreadyConsumed = "already_consumed"
	ReasonNoRelation      = "no_invite_relation"
	ReasonDuplicate       = "duplicate"

	EventTypeWalletRechargeRecorded = "WalletRechargeRecorded"
	EventTypeUserInvited            = "UserInvited"
	EventTypeUserInviteBecameValid  = "UserInviteBecameValid"
)

// Tier 是邀请活动的金币奖励档位；不同 reward_type 使用不同门槛字段。
type Tier struct {
	TierID                    int64
	AppCode                   string
	RewardType                string
	TierCode                  string
	TierName                  string
	ThresholdCoinAmount       int64
	ThresholdValidInviteCount int64
	RewardCoinAmount          int64
	Status                    string
	SortOrder                 int32
	CreatedAtMS               int64
	UpdatedAtMS               int64
}

// Config 是当前 App 的邀请活动配置。
type Config struct {
	AppCode                          string
	Enabled                          bool
	PerInviteInviterRewardCoinAmount int64
	PerInviteInviteeRewardCoinAmount int64
	Tiers                            []Tier
	UpdatedByAdminID                 int64
	CreatedAtMS                      int64
	UpdatedAtMS                      int64
}

// Progress 是邀请人在一个 UTC 自然月内的邀请活动累计。
type Progress struct {
	AppCode                 string
	CycleKey                string
	UserID                  int64
	TotalRechargeCoinAmount int64
	ValidInviteCount        int64
	ClaimedRewardCoinAmount int64
	UpdatedAtMS             int64
}

// Claim 是用户点击领取后创建的钱包发奖事实。
type Claim struct {
	ClaimID                   string
	AppCode                   string
	CycleKey                  string
	UserID                    int64
	RewardType                string
	CommandID                 string
	TierID                    int64
	TierCode                  string
	TierName                  string
	ThresholdCoinAmount       int64
	ThresholdValidInviteCount int64
	ReachedValue              int64
	RewardCoinAmount          int64
	Status                    string
	WalletCommandID           string
	WalletTransactionID       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
	InvitedUserID      int64
	InviterUserID      int64
	RechargeCoinAmount int64
	RechargeType       string
	PayloadJSON        string
	OccurredAtMS       int64
}

// ValidInviteEvent 是 user_outbox 里“被邀请用户首次成为有效邀请”的事实。
type ValidInviteEvent struct {
	AppCode       string
	EventID       string
	EventType     string
	InvitedUserID int64
	InviterUserID int64
	PayloadJSON   string
	OccurredAtMS  int64
}

// InviteEvent 是 user_outbox 里“邀请关系首次绑定”的事实；它不依赖被邀请人后续是否充值达标。
type InviteEvent struct {
	AppCode       string
	EventID       string
	EventType     string
	InvitedUserID int64
	InviterUserID int64
	InviteCode    string
	Source        string
	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
	Claims       []Claim
	Cycle        Cycle
	ServerTimeMS int64
}

// ConsumeResult 表达一次事件是否被写入进度。
type ConsumeResult struct {
	Consumed bool
	Reason   string
}

// ClaimQuery 是后台领取记录查询条件。
type ClaimQuery struct {
	Status     string
	RewardType string
	UserID     int64
	CycleKey   string
	Page       int32
	PageSize   int32
}

// Summary 是后台邀请活动列表的一行，按邀请人和周期聚合邀请人数、有效人数、充值和奖励。
type Summary struct {
	AppCode                 string
	CycleKey                string
	UserID                  int64
	InviteCount             int64
	ValidInviteCount        int64
	TotalRechargeCoinAmount int64
	TotalRewardCoinAmount   int64
	UpdatedAtMS             int64
	Invitees                []InviteeSummary
}

// InviteeSummary 是后台聚合行展开后的被邀请人明细，按被邀请人聚合充值并保留首次邀请时间。
type InviteeSummary struct {
	InvitedUserID      int64
	RechargeCoinAmount int64
	InvitedAtMS        int64
}

// InviteeQuery 是 App 当前用户邀请明细的有界分页条件；CycleKey 由 service 固定为当前 UTC 月。
type InviteeQuery struct {
	UserID   int64
	CycleKey string
	Page     int32
	PageSize int32
}

type InviteeResult struct {
	Invitees     []InviteeSummary
	Total        int64
	Page         int32
	PageSize     int32
	CycleKey     string
	ServerTimeMS int64
}

// SummaryQuery 是后台邀请活动聚合列表查询条件；UserID 只过滤邀请人，CycleKey 为空表示所有周期。
type SummaryQuery struct {
	UserID   int64
	CycleKey string
	Page     int32
	PageSize int32
}

// LeaderboardEntry 是邀请活动月榜的一行，只统计已经达到有效邀请标准的邀请人数。
type LeaderboardEntry struct {
	RankNo                  int32
	UserID                  int64
	ValidInviteCount        int64
	TotalRechargeCoinAmount int64
}

// LeaderboardQuery 是邀请活动月榜分页条件；CycleKey 为空时由 service 使用当前 UTC 月。
type LeaderboardQuery struct {
	CycleKey string
	Page     int32
	PageSize int32
}

// LeaderboardResult 是邀请活动月榜查询结果。
type LeaderboardResult struct {
	Entries      []LeaderboardEntry
	Total        int64
	CycleKey     string
	ServerTimeMS int64
}
