package task

const (
	TypeDaily     = "daily"
	TypeExclusive = "exclusive"

	SectionDaily     = "daily"
	SectionExclusive = "exclusive"

	CycleLifetime = "lifetime"

	AudienceAll    = "all"
	AudienceNewbie = "newbie"

	ActionNone              = "none"
	ActionRoom              = "room"
	ActionRoomRandom        = "room_random"
	ActionRoomWindow        = "room_window"
	ActionRoomRandomWindow  = "room_random_window"
	ActionRoomGame          = "room_game"
	ActionRoomRandomGame    = "room_random_game"
	ActionExploreGame       = "explore_game"
	ActionWallet            = "wallet"
	ActionGiftPanel         = "gift_panel"
	ActionGiftPanelSpecific = "gift_panel_specific"

	MetricGameSpendCoin         = "game_spend_coin"
	MetricGameDicePlayCount     = "game_dice_play_count"
	MetricGameRockPlayCount     = "game_rock_play_count"
	MetricGiftSpendCoin         = "gift_spend_coin"
	MetricGiftSendCount         = "gift_send_count"
	MetricLuckyGiftSpendCoin    = "lucky_gift_spend_coin"
	MetricLuckyGiftSendCount    = "lucky_gift_send_count"
	MetricRechargeCoin          = "recharge_coin"
	MetricCPRelationshipCreated = "cp_relationship_created"
	MetricMicOnlineMinute       = "mic_online_minute"
	MetricMoodPublishCount      = "mood_publish_count"

	StatusDraft      = "draft"
	StatusActive     = "active"
	StatusPaused     = "paused"
	StatusArchived   = "archived"
	StatusInProgress = "in_progress"
	StatusCompleted  = "completed"
	StatusClaimed    = "claimed"
	StatusExpired    = "expired"

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

	EventStatusConsumed = "consumed"
	EventStatusSkipped  = "skipped"
	EventStatusFailed   = "failed"

	RewardAssetCoin  = "COIN"
	RewardAssetPoint = "POINT"

	RewardTypeWalletAsset   = "wallet_asset"
	RewardTypeResource      = "resource"
	RewardTypeResourceGroup = "resource_group"

	RewardItemTypeResource    = "resource"
	RewardItemTypeWalletAsset = "wallet_asset"
)

// RewardItem 是任务定义在保存时固化的奖励展示快照；H5 只依赖封面和数量，不从名称反推资源语义。
type RewardItem struct {
	ItemType          string `json:"item_type"`
	ResourceID        int64  `json:"resource_id,omitempty"`
	ResourceType      string `json:"resource_type,omitempty"`
	CoverURL          string `json:"cover_url,omitempty"`
	Quantity          int64  `json:"quantity,omitempty"`
	DurationMS        int64  `json:"duration_ms,omitempty"`
	WalletAssetType   string `json:"wallet_asset_type,omitempty"`
	WalletAssetAmount int64  `json:"wallet_asset_amount,omitempty"`
}

// Definition 是 task_definitions 的当前版本读模型；App 查询只读这张表和用户进度表。
type Definition struct {
	AppCode               string
	TaskID                string
	TaskType              string
	Category              string
	MetricType            string
	Title                 string
	Description           string
	AudienceType          string
	IconKey               string
	IconURL               string
	ActionType            string
	ActionParam           string
	ActionPayloadJSON     string
	DimensionFilterJSON   string
	TargetValue           int64
	TargetUnit            string
	RewardType            string
	RewardCoinAmount      int64
	RewardAssetType       string
	RewardResourceID      int64
	RewardResourceGroupID int64
	RewardSnapshotID      string
	RewardSnapshotHash    string
	RewardQuantity        int64
	RewardDurationMS      int64
	RewardItemsJSON       string
	Status                string
	SortOrder             int32
	Version               int64
	CurrentVersionID      int64
	EffectiveFromMS       int64
	EffectiveToMS         int64
	CreatedByAdminID      int64
	UpdatedByAdminID      int64
	CreatedAtMS           int64
	UpdatedAtMS           int64
}

// Progress 是 user_task_progress 的用户维度状态；target/reward 使用创建进度时的任务快照。
type Progress struct {
	AppCode               string
	UserID                int64
	TaskID                string
	TaskVersionID         int64
	CycleKey              string
	ProgressValue         int64
	TargetValue           int64
	RewardType            string
	RewardCoinAmount      int64
	RewardAssetType       string
	RewardResourceID      int64
	RewardResourceGroupID int64
	RewardSnapshotID      string
	RewardSnapshotHash    string
	RewardQuantity        int64
	RewardDurationMS      int64
	RewardItemsJSON       string
	Status                string
	CompletedAtMS         int64
	ClaimedAtMS           int64
	UpdatedAtMS           int64
}

// Item 是 App 任务列表返回前的领域快照。
type Item struct {
	Definition
	ProgressValue   int64
	UserStatus      string
	Claimable       bool
	TaskDay         string
	ServerTimeMS    int64
	NextRefreshAtMS int64
}

// Section 是 daily/exclusive 的固定分区。
type Section struct {
	Section         string
	Items           []Item
	ServerTimeMS    int64
	NextRefreshAtMS int64
}

// ListResult 是 App 任务页的完整只读结果。
type ListResult struct {
	Sections        []Section
	ServerTimeMS    int64
	NextRefreshAtMS int64
}

// DefinitionQuery 是后台任务配置列表筛选条件。
type DefinitionQuery struct {
	TaskType string
	Category string
	Status   string
	Keyword  string
	Page     int32
	PageSize int32
}

// DefinitionCommand 是后台创建/编辑任务定义的命令快照。
type DefinitionCommand struct {
	TaskID                string
	TaskType              string
	Category              string
	MetricType            string
	Title                 string
	Description           string
	AudienceType          string
	IconKey               string
	IconURL               string
	ActionType            string
	ActionParam           string
	ActionPayloadJSON     string
	DimensionFilterJSON   string
	TargetValue           int64
	TargetUnit            string
	RewardType            string
	RewardCoinAmount      int64
	RewardAssetType       string
	RewardResourceID      int64
	RewardResourceGroupID int64
	RewardSnapshotID      string
	RewardSnapshotHash    string
	RewardQuantity        int64
	RewardDurationMS      int64
	RewardItemsJSON       string
	Status                string
	SortOrder             int32
	EffectiveFromMS       int64
	EffectiveToMS         int64
	OperatorAdminID       int64
}

// Event 是由 wallet/user/room outbox 派生的任务进度事实。
type Event struct {
	EventID        string
	EventType      string
	SourceService  string
	UserID         int64
	MetricType     string
	Value          int64
	OccurredAtMS   int64
	DimensionsJSON string
}

// EventResult 表达事件消费幂等结果。
type EventResult struct {
	EventID          string
	Status           string
	MatchedTaskCount int32
}

// ClaimCommand 是用户领取任务奖励的幂等命令。
type ClaimCommand struct {
	UserID    int64
	TaskID    string
	TaskType  string
	CycleKey  string
	CommandID string
}

// Claim 是 task_reward_claims 的领奖事实。
type Claim struct {
	ClaimID               string
	CommandID             string
	UserID                int64
	TaskID                string
	TaskType              string
	CycleKey              string
	RewardType            string
	RewardCoinAmount      int64
	RewardAssetType       string
	RewardResourceID      int64
	RewardResourceGroupID int64
	RewardSnapshotID      string
	RewardSnapshotHash    string
	RewardQuantity        int64
	RewardDurationMS      int64
	RewardItemsJSON       string
	WalletCommandID       string
	WalletTransactionID   string
	WalletResourceGrantID string
	Status                string
	FailureReason         string
	CreatedAtMS           int64
	UpdatedAtMS           int64
}
