package activitytemplate

const (
	TaskStatusInProgress = "in_progress"
	TaskStatusCompleted  = "completed"
	TaskStatusClaimed    = "claimed"

	ClaimStatusPending = "pending"
	ClaimStatusRunning = "running"
	ClaimStatusGranted = "granted"
	ClaimStatusFailed  = "failed"
	ClaimStatusDead    = "dead"

	PeriodStatusPending   = "pending"
	PeriodStatusSettling  = "settling"
	PeriodStatusRewarding = "rewarding"
	PeriodStatusSettled   = "settled"
	PeriodStatusCancelled = "cancelled"

	EventStatusConsumed = "consumed"
	EventStatusSkipped  = "skipped"
)

// Runtime 是一次发布形成的不可变运行版本及其真实启停窗口。
// Template 来自 activity_template_versions.snapshot_json，不读取后台当前编辑态。
type Runtime struct {
	Template      Template
	VersionNo     int64
	RuntimeFromMS int64
	RuntimeToMS   int64
}

// GiftEvent 是 room-service 已提交并完成钱包扣费的送礼事实。
type GiftEvent struct {
	EventID      string
	UserID       int64
	GiftID       string
	GiftCount    int64
	CoinAmount   int64
	RegionID     int64
	OccurredAtMS int64
}

type EventResult struct {
	EventID      string
	Status       string
	SkipReason   string
	TemplateID   string
	TemplateCode string
	VersionNo    int64
	TaskDay      string
}

// TaskProgress 固化任务目标和奖励资源组，后台后续发布新版本不会改变已产生的进度与领奖内容。
type TaskProgress struct {
	AppCode               string
	TemplateID            string
	TemplateCode          string
	VersionNo             int64
	TaskDay               string
	UserID                int64
	TaskKey               string
	TaskType              string
	TargetValue           int64
	ProgressValue         int64
	RewardResourceGroupID int64
	RewardSnapshot        RewardSnapshot
	SortOrder             int32
	Status                string
	CompletedAtMS         int64
	ClaimedAtMS           int64
	UpdatedAtMS           int64
	FirstRegionID         int64
	EarningRegionID       int64
	AttributionAtMS       int64
}

type VisitCommand struct {
	UserID       int64
	RegionID     int64
	TemplateCode string
	CommandID    string
	VersionNo    int64
}

type VisitResult struct {
	Runtime    Runtime
	Tasks      []TaskProgress
	FirstVisit bool
}

type ClaimCommand struct {
	UserID       int64
	RegionID     int64
	TemplateCode string
	VersionNo    int64
	TaskDay      string
	TaskKey      string
	CommandID    string
}

type TaskClaim struct {
	AppCode               string
	ClaimID               string
	CommandID             string
	TemplateID            string
	TemplateCode          string
	VersionNo             int64
	TaskDay               string
	TaskKey               string
	UserID                int64
	RewardResourceGroupID int64
	RewardSnapshot        RewardSnapshot
	WalletCommandID       string
	WalletGrantID         string
	Status                string
	FailureReason         string
	AttemptCount          int32
	CreatedAtMS           int64
	UpdatedAtMS           int64
	GrantedAtMS           int64
	EarningRegionID       int64
	AttributionAtMS       int64
}

type TaskClaimQuery struct {
	TemplateID string
	VersionNo  int64
	TaskDay    string
	TaskKey    string
	UserID     int64
	Status     string
	Page       int32
	PageSize   int32
}

type LeaderboardEntry struct {
	RankNo          int32
	UserID          int64
	Score           int64
	GiftCount       int64
	CoinAmount      int64
	FirstScoredAtMS int64
	Snapshot        bool
}

type RankPeriod struct {
	AppCode         string
	TemplateID      string
	TemplateCode    string
	VersionNo       int64
	BoardType       string
	PeriodKey       string
	StartMS         int64
	EndMS           int64
	SettleAfterMS   int64
	LeaderboardSize int32
	Status          string
	SettledAtMS     int64
}

type LeaderboardQuery struct {
	TemplateID   string
	TemplateCode string
	VersionNo    int64
	RegionID     int64
	UserID       int64
	BoardType    string
	PeriodKey    string
	Page         int32
	PageSize     int32
	NowMS        int64
}

type LeaderboardResult struct {
	Runtime Runtime
	Period  RankPeriod
	Entries []LeaderboardEntry
	MyEntry LeaderboardEntry
	MyFound bool
	Total   int64
}

type RewardJob struct {
	AppCode         string
	RewardJobID     string
	TemplateID      string
	TemplateCode    string
	VersionNo       int64
	BoardType       string
	PeriodKey       string
	RankNo          int32
	UserID          int64
	Score           int64
	ResourceGroupID int64
	RewardSnapshot  RewardSnapshot
	WalletCommandID string
	WalletGrantID   string
	Status          string
	FailureReason   string
	AttemptCount    int32
	MaxAttempts     int32
	NextRetryAtMS   int64
	CreatedAtMS     int64
	UpdatedAtMS     int64
	GrantedAtMS     int64
}

type RewardJobQuery struct {
	TemplateID string
	VersionNo  int64
	BoardType  string
	PeriodKey  string
	Status     string
	Page       int32
	PageSize   int32
}

// StatsOutboxRecord 是投递到 statistics-service 的 owner 事实；业务事务只写本地 outbox，MQ 失败不回滚计分。
type StatsOutboxRecord struct {
	OutboxID   string
	EventType  string
	Payload    []byte
	RetryCount int32
}
