package weeklystar

const (
	// ActivityCode 是通用指定礼物积分活动框架中用于承载周星的活动编码。
	ActivityCode = "weekly_star"

	StatusDraft    = "draft"
	StatusActive   = "active"
	StatusDisabled = "disabled"
	StatusSettling = "settling"
	StatusSettled  = "settled"

	EventStatusConsumed  = "consumed"
	EventStatusSkipped   = "skipped"
	EventStatusDuplicate = "duplicate"

	SettlementStatusPending = "pending"
	SettlementStatusRunning = "running"
	SettlementStatusGranted = "granted"
	SettlementStatusFailed  = "failed"

	GrantSourceWeeklyStar = "weekly_star"
)

// Gift describes one gift that can add score inside a weekly star cycle.
type Gift struct {
	AppCode   string
	CycleID   string
	GiftID    string
	SortOrder int32
}

// Reward maps one weekly star rank to the resource group granted at settlement time.
type Reward struct {
	AppCode         string
	CycleID         string
	RankNo          int32
	ResourceGroupID int64
}

// Cycle is the region-scoped UTC time window that controls weekly star scoring and rewards.
type Cycle struct {
	AppCode          string
	CycleID          string
	ActivityCode     string
	RegionID         int64
	Title            string
	Status           string
	StartMS          int64
	EndMS            int64
	CreatedByAdminID int64
	UpdatedByAdminID int64
	SettledAtMS      int64
	CreatedAtMS      int64
	UpdatedAtMS      int64
	Gifts            []Gift
	Rewards          []Reward
}

// CycleCommand is the admin mutation input after transport normalization.
type CycleCommand struct {
	Cycle            Cycle
	OperatorAdminID  int64
	RequireNewRecord bool
}

// ListQuery filters admin cycle list reads. Region 0 is a real filter for default cycles.
type ListQuery struct {
	RegionID *int64
	Status   string
	StartMS  int64
	EndMS    int64
	Page     int32
	PageSize int32
}

// GiftEvent is the committed room-service gift fact consumed by weekly star.
type GiftEvent struct {
	EventID      string
	UserID       int64
	GiftID       string
	ScoreDelta   int64
	RegionID     int64
	OccurredAtMS int64
}

// EventResult describes idempotent score consumption for one source event.
type EventResult struct {
	EventID    string
	Status     string
	CycleID    string
	ScoreDelta int64
}

// LeaderboardEntry is the score row plus deterministic rank within a cycle.
type LeaderboardEntry struct {
	RankNo          int32
	UserID          int64
	Score           int64
	FirstScoredAtMS int64
	LastScoredAtMS  int64
}

// Settlement is one resource-group grant job for a settled Top rank.
type Settlement struct {
	AppCode         string
	SettlementID    string
	CycleID         string
	RankNo          int32
	UserID          int64
	Score           int64
	ResourceGroupID int64
	WalletCommandID string
	WalletGrantID   string
	Status          string
	FailureReason   string
	AttemptCount    int32
	CreatedAtMS     int64
	UpdatedAtMS     int64
}

// HistoryCycle groups a completed cycle with its Top entries for H5 history reads.
type HistoryCycle struct {
	Cycle      Cycle
	TopEntries []LeaderboardEntry
}
