syntax = "proto3";

package hyapp.activity.v1;

import "proto/events/room/v1/events.proto";

option go_package = "hyapp.local/api/proto/activity/v1;activityv1";

// RequestMeta 是 activity-service 内部 RPC 的最小追踪元信息。
message RequestMeta {
  string request_id = 1;
  string caller = 2;
  string gateway_node_id = 3;
  int64 sent_at_ms = 4;
  string app_code = 5;
}

// PingActivityRequest 用于验证 activity-service gRPC 链路可用。
message PingActivityRequest {
  RequestMeta meta = 1;
}

// PingActivityResponse 返回服务是否接受请求。
message PingActivityResponse {
  bool ok = 1;
  string node_id = 2;
}

// GetActivityStatusRequest 查询活动服务底座状态。
message GetActivityStatusRequest {
  RequestMeta meta = 1;
  string activity_id = 2;
}

// GetActivityStatusResponse 返回活动是否启用。
message GetActivityStatusResponse {
  string activity_id = 1;
  string status = 2;
}

// MessageTabSection 是 App 消息 tab 的一个分区摘要。
message MessageTabSection {
  string section = 1;
  string title = 2;
  int64 unread_count = 3;
  string source = 4;
}

// ListMessageTabsRequest 查询当前用户消息 tab 摘要。
message ListMessageTabsRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
}

// ListMessageTabsResponse 固定返回 user/system/activity 三个分区。
message ListMessageTabsResponse {
  repeated MessageTabSection sections = 1;
}

// InboxMessage 是 system/activity 分区列表可展示的消息快照。
message InboxMessage {
  string message_id = 1;
  string section = 2;
  string title = 3;
  string summary = 4;
  string body = 5;
  string icon_url = 6;
  string image_url = 7;
  string action_type = 8;
  string action_param = 9;
  bool read = 10;
  int64 sent_at_ms = 11;
}

// ListInboxMessagesRequest 按 section 和游标分页读取当前用户 inbox。
message ListInboxMessagesRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string section = 3;
  int32 page_size = 4;
  string page_token = 5;
}

// ListInboxMessagesResponse 返回当前页列表和下一页不透明游标。
message ListInboxMessagesResponse {
  string section = 1;
  repeated InboxMessage items = 2;
  string next_page_token = 3;
}

// MarkInboxMessageReadRequest 标记单条消息已读。
message MarkInboxMessageReadRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string message_id = 3;
}

// MarkInboxMessageReadResponse 返回消息首次已读时间；重复请求不覆盖该时间。
message MarkInboxMessageReadResponse {
  string message_id = 1;
  bool read = 2;
  int64 read_at_ms = 3;
}

// MarkInboxSectionReadRequest 标记一个 section 下当前可见未读消息全部已读。
message MarkInboxSectionReadRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string section = 3;
}

// MarkInboxSectionReadResponse 返回本次实际变更的消息数量。
message MarkInboxSectionReadResponse {
  string section = 1;
  int64 read_count = 2;
}

// DeleteInboxMessageRequest 删除当前用户可见消息，删除是用户侧隐藏。
message DeleteInboxMessageRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string message_id = 3;
}

// DeleteInboxMessageResponse 返回被隐藏的消息 ID。
message DeleteInboxMessageResponse {
  string message_id = 1;
  bool deleted = 2;
}

// CreateInboxMessageRequest 是生产者入箱命令；producer_event_id 是幂等键。
message CreateInboxMessageRequest {
  RequestMeta meta = 1;
  int64 target_user_id = 2;
  string producer = 3;
  string producer_event_id = 4;
  string producer_event_type = 5;
  string message_type = 6;
  string aggregate_type = 7;
  string aggregate_id = 8;
  string template_id = 9;
  string template_version = 10;
  string title = 11;
  string summary = 12;
  string body = 13;
  string icon_url = 14;
  string image_url = 15;
  string action_type = 16;
  string action_param = 17;
  int32 priority = 18;
  int64 sent_at_ms = 19;
  int64 expire_at_ms = 20;
  string metadata_json = 21;
}

// CreateInboxMessageResponse 返回入箱结果；重复同一 producer_event_id 时 created=false。
message CreateInboxMessageResponse {
  string message_id = 1;
  bool created = 2;
}

// CreateFanoutJobRequest 创建后台 fanout 任务；command_id 是后台命令幂等键。
message CreateFanoutJobRequest {
  RequestMeta meta = 1;
  string command_id = 2;
  string message_type = 3;
  string target_scope = 4;
  string target_filter_json = 5;
  string template_snapshot_json = 6;
  int32 batch_size = 7;
  string created_by = 8;
}

// CreateFanoutJobResponse 返回 fanout job 幂等创建结果。
message CreateFanoutJobResponse {
  string job_id = 1;
  string status = 2;
  bool created = 3;
}

// CronBatchRequest 是 cron-service 触发 activity-service 后台批处理的统一请求。
message CronBatchRequest {
  RequestMeta meta = 1;
  string run_id = 2;
  string worker_id = 3;
  int32 batch_size = 4;
  int64 lock_ttl_ms = 5;
}

// CronBatchResponse 返回一个批处理 run 的执行摘要。
message CronBatchResponse {
  int32 claimed_count = 1;
  int32 processed_count = 2;
  int32 success_count = 3;
  int32 failure_count = 4;
  bool has_more = 5;
}

// TaskItem 是 App 每日任务/专属任务列表里的单个可展示任务快照。
message TaskItem {
  string task_id = 1;
  string task_type = 2;
  string category = 3;
  string metric_type = 4;
  string title = 5;
  string description = 6;
  int64 target_value = 7;
  string target_unit = 8;
  int64 progress_value = 9;
  int64 reward_coin_amount = 10;
  string status = 11;
  bool claimable = 12;
  string task_day = 13;
  int64 server_time_ms = 14;
  int64 next_refresh_at_ms = 15;
  int32 sort_order = 16;
  int64 version = 17;
}

// TaskSection 固定表达 App 任务页的 daily/exclusive 两个分区。
message TaskSection {
  string section = 1;
  repeated TaskItem items = 2;
  int64 server_time_ms = 3;
  int64 next_refresh_at_ms = 4;
}

// ListUserTasksRequest 查询当前用户任务进度；进度必须来自服务端事实事件。
message ListUserTasksRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
}

// ListUserTasksResponse 返回 daily/exclusive 分区和服务器刷新时间。
message ListUserTasksResponse {
  repeated TaskSection sections = 1;
  int64 server_time_ms = 2;
  int64 next_refresh_at_ms = 3;
}

// ClaimTaskRewardRequest 领取已完成任务奖励；command_id 是领奖幂等键。
message ClaimTaskRewardRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string task_id = 3;
  string task_type = 4;
  string task_day = 5;
  string command_id = 6;
}

// ClaimTaskRewardResponse 返回 activity 领奖状态和 wallet 入账回执。
message ClaimTaskRewardResponse {
  string claim_id = 1;
  string task_id = 2;
  string task_type = 3;
  string task_day = 4;
  int64 reward_coin_amount = 5;
  string status = 6;
  string wallet_transaction_id = 7;
  int64 granted_at_ms = 8;
  bool claimed = 9;
}

// ConsumeTaskEventRequest 是异步 outbox consumer 投递给任务系统的事实事件。
message ConsumeTaskEventRequest {
  RequestMeta meta = 1;
  string event_id = 2;
  string event_type = 3;
  string source_service = 4;
  int64 user_id = 5;
  string metric_type = 6;
  int64 value = 7;
  int64 occurred_at_ms = 8;
}

// ConsumeTaskEventResponse 返回事件消费幂等结果；matched_task_count=0 表示合法跳过。
message ConsumeTaskEventResponse {
  string event_id = 1;
  string status = 2;
  int32 matched_task_count = 3;
}

// BroadcastJoinGroup 是 gateway 下发给客户端的 IM 播报群信息在服务端的同源结构。
message BroadcastJoinGroup {
  string group_id = 1;
  string type = 2;
  int64 region_id = 3;
}

message EnsureBroadcastGroupsRequest {
  RequestMeta meta = 1;
}

message EnsureBroadcastGroupsResponse {
  int32 ensured_count = 1;
}

message PublishRegionBroadcastRequest {
  RequestMeta meta = 1;
  string event_id = 2;
  int64 region_id = 3;
  string broadcast_type = 4;
  string payload_json = 5;
}

message PublishGlobalBroadcastRequest {
  RequestMeta meta = 1;
  string event_id = 2;
  string broadcast_type = 3;
  string payload_json = 4;
}

message PublishBroadcastResponse {
  string event_id = 1;
  string group_id = 2;
  string status = 3;
  bool created = 4;
}

// RemoveRegionBroadcastMemberRequest 只移除某个用户的旧区域群成员关系，不删除或解散区域群。
message RemoveRegionBroadcastMemberRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  int64 region_id = 3;
  string reason = 4;
}

message RemoveRegionBroadcastMemberResponse {
  string group_id = 1;
  bool removed = 2;
}

message ProcessBroadcastOutboxBatchResponse {
  int32 claimed_count = 1;
  int32 success_count = 2;
  int32 failure_count = 3;
  bool has_more = 4;
}

message ConsumeRoomEventRequest {
  RequestMeta meta = 1;
  hyapp.events.room.v1.EventEnvelope envelope = 2;
}

message ConsumeRoomEventResponse {
  string event_id = 1;
  string status = 2;
  string broadcast_event_id = 3;
  bool broadcast_created = 4;
}

// TaskDefinition 是后台管理任务配置的当前版本读模型。
message TaskDefinition {
  string task_id = 1;
  string task_type = 2;
  string category = 3;
  string metric_type = 4;
  string title = 5;
  string description = 6;
  int64 target_value = 7;
  string target_unit = 8;
  int64 reward_coin_amount = 9;
  string status = 10;
  int32 sort_order = 11;
  int64 version = 12;
  int64 effective_from_ms = 13;
  int64 effective_to_ms = 14;
  int64 created_by_admin_id = 15;
  int64 updated_by_admin_id = 16;
  int64 created_at_ms = 17;
  int64 updated_at_ms = 18;
}

// ListTaskDefinitionsRequest 是后台任务配置列表筛选条件。
message ListTaskDefinitionsRequest {
  RequestMeta meta = 1;
  string task_type = 2;
  string category = 3;
  string status = 4;
  string keyword = 5;
  int32 page = 6;
  int32 page_size = 7;
}

message ListTaskDefinitionsResponse {
  repeated TaskDefinition tasks = 1;
  int64 total = 2;
}

// UpsertTaskDefinitionRequest 创建或编辑任务；active 关键字段变更由服务端生成新版本。
message UpsertTaskDefinitionRequest {
  RequestMeta meta = 1;
  string task_id = 2;
  string task_type = 3;
  string category = 4;
  string metric_type = 5;
  string title = 6;
  string description = 7;
  int64 target_value = 8;
  string target_unit = 9;
  int64 reward_coin_amount = 10;
  string status = 11;
  int32 sort_order = 12;
  int64 effective_from_ms = 13;
  int64 effective_to_ms = 14;
  int64 operator_admin_id = 15;
}

message UpsertTaskDefinitionResponse {
  TaskDefinition task = 1;
  bool created = 2;
}

// SetTaskDefinitionStatusRequest 后台启停或归档任务，不做物理删除。
message SetTaskDefinitionStatusRequest {
  RequestMeta meta = 1;
  string task_id = 2;
  string status = 3;
  int64 operator_admin_id = 4;
}

message SetTaskDefinitionStatusResponse {
  TaskDefinition task = 1;
}

// RegistrationRewardConfig 是注册奖励的当前配置；enabled=false 时保留配置但不自动发放。
message RegistrationRewardConfig {
  string app_code = 1;
  bool enabled = 2;
  string reward_type = 3;
  int64 coin_amount = 4;
  int64 resource_group_id = 5;
  int64 daily_limit = 6;
  int64 updated_by_admin_id = 7;
  int64 created_at_ms = 8;
  int64 updated_at_ms = 9;
}

// RegistrationRewardClaim 是每个用户注册奖励的领取事实；user_id 唯一保证“没有领过”。
message RegistrationRewardClaim {
  string claim_id = 1;
  string command_id = 2;
  int64 user_id = 3;
  string reward_day = 4;
  string reward_type = 5;
  int64 coin_amount = 6;
  int64 resource_group_id = 7;
  string status = 8;
  string wallet_command_id = 9;
  string wallet_transaction_id = 10;
  string resource_grant_id = 11;
  string failure_reason = 12;
  int64 claimed_at_ms = 13;
  int64 created_at_ms = 14;
  int64 updated_at_ms = 15;
}

// RegistrationRewardEligibility 返回 App 可直接展示的资格判断；每日份数按 UTC reward_day 统计。
message RegistrationRewardEligibility {
  bool can_receive = 1;
  string reason = 2;
  bool enabled = 3;
  string reward_type = 4;
  int64 coin_amount = 5;
  int64 resource_group_id = 6;
  int64 daily_limit = 7;
  int64 daily_used = 8;
  int64 daily_remaining = 9;
  string reward_day = 10;
  int64 server_time_ms = 11;
}

// GetRegistrationRewardEligibilityRequest 给 App 查询当前用户是否还有注册奖励资格。
message GetRegistrationRewardEligibilityRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
}

message GetRegistrationRewardEligibilityResponse {
  RegistrationRewardEligibility eligibility = 1;
}

// IssueRegistrationRewardRequest 是 user-service 注册成功后调用的幂等发放命令。
message IssueRegistrationRewardRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string command_id = 3;
}

message IssueRegistrationRewardResponse {
  RegistrationRewardClaim claim = 1;
  RegistrationRewardEligibility eligibility = 2;
  bool issued = 3;
}

// GetRegistrationRewardConfigRequest 返回后台注册奖励配置；未配置时服务端返回默认 disabled 配置。
message GetRegistrationRewardConfigRequest {
  RequestMeta meta = 1;
}

message GetRegistrationRewardConfigResponse {
  RegistrationRewardConfig config = 1;
}

// UpdateRegistrationRewardConfigRequest 更新注册奖励开关、奖励内容和每日限制。
message UpdateRegistrationRewardConfigRequest {
  RequestMeta meta = 1;
  bool enabled = 2;
  string reward_type = 3;
  int64 coin_amount = 4;
  int64 resource_group_id = 5;
  int64 daily_limit = 6;
  int64 operator_admin_id = 7;
}

message UpdateRegistrationRewardConfigResponse {
  RegistrationRewardConfig config = 1;
}

// ListRegistrationRewardClaimsRequest 是后台领取记录分页筛选；keyword 由 admin-server 结合用户库扩展。
message ListRegistrationRewardClaimsRequest {
  RequestMeta meta = 1;
  string status = 2;
  int64 user_id = 3;
  int32 page = 4;
  int32 page_size = 5;
  int64 claimed_start_ms = 6;
  int64 claimed_end_ms = 7;
}

message ListRegistrationRewardClaimsResponse {
  repeated RegistrationRewardClaim claims = 1;
  int64 total = 2;
  int64 today_claimed_count = 3;
}

// FirstRechargeRewardTier 是首冲奖励的一个金币充值档位；max_coin_amount=0 表示无上限。
message FirstRechargeRewardTier {
  int64 tier_id = 1;
  string tier_code = 2;
  string tier_name = 3;
  int64 min_coin_amount = 4;
  int64 max_coin_amount = 5;
  int64 resource_group_id = 6;
  string status = 7;
  int32 sort_order = 8;
  int64 created_at_ms = 9;
  int64 updated_at_ms = 10;
}

// FirstRechargeRewardConfig 是当前 App 的首冲奖励配置；档位内容在 activity-service 内保持版本一致。
message FirstRechargeRewardConfig {
  string app_code = 1;
  bool enabled = 2;
  repeated FirstRechargeRewardTier tiers = 3;
  int64 updated_by_admin_id = 4;
  int64 created_at_ms = 5;
  int64 updated_at_ms = 6;
}

// FirstRechargeRewardClaim 是某个用户首笔充值触发后的发奖事实；user_id 唯一保证一生只处理一次。
message FirstRechargeRewardClaim {
  string claim_id = 1;
  string event_id = 2;
  string transaction_id = 3;
  string command_id = 4;
  int64 user_id = 5;
  int64 tier_id = 6;
  string tier_code = 7;
  int64 resource_group_id = 8;
  int64 recharge_coin_amount = 9;
  int64 recharge_sequence = 10;
  string recharge_type = 11;
  string status = 12;
  string wallet_command_id = 13;
  string wallet_grant_id = 14;
  string failure_reason = 15;
  int64 recharged_at_ms = 16;
  int64 granted_at_ms = 17;
  int64 created_at_ms = 18;
  int64 updated_at_ms = 19;
}

// FirstRechargeRewardStatus 是 App 首冲奖励面板可直接展示的当前状态。
message FirstRechargeRewardStatus {
  bool enabled = 1;
  repeated FirstRechargeRewardTier tiers = 2;
  bool rewarded = 3;
  FirstRechargeRewardClaim claim = 4;
  int64 server_time_ms = 5;
}

message GetFirstRechargeRewardStatusRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
}

message GetFirstRechargeRewardStatusResponse {
  FirstRechargeRewardStatus status = 1;
}

// ConsumeFirstRechargeRewardRequest 是 wallet 充值事实消费入口；只处理 recharge_sequence=1 的成功充值。
message ConsumeFirstRechargeRewardRequest {
  RequestMeta meta = 1;
  string event_id = 2;
  string transaction_id = 3;
  string command_id = 4;
  int64 user_id = 5;
  int64 recharge_coin_amount = 6;
  int64 recharge_sequence = 7;
  string recharge_type = 8;
  int64 occurred_at_ms = 9;
}

message ConsumeFirstRechargeRewardResponse {
  FirstRechargeRewardClaim claim = 1;
  bool consumed = 2;
  string reason = 3;
}

message GetFirstRechargeRewardConfigRequest {
  RequestMeta meta = 1;
}

message GetFirstRechargeRewardConfigResponse {
  FirstRechargeRewardConfig config = 1;
}

message UpdateFirstRechargeRewardConfigRequest {
  RequestMeta meta = 1;
  bool enabled = 2;
  repeated FirstRechargeRewardTier tiers = 3;
  int64 operator_admin_id = 4;
}

message UpdateFirstRechargeRewardConfigResponse {
  FirstRechargeRewardConfig config = 1;
}

message ListFirstRechargeRewardClaimsRequest {
  RequestMeta meta = 1;
  string status = 2;
  int64 user_id = 3;
  int32 page = 4;
  int32 page_size = 5;
}

message ListFirstRechargeRewardClaimsResponse {
  repeated FirstRechargeRewardClaim claims = 1;
  int64 total = 2;
}

// CumulativeRechargeRewardTier 是累充奖励的单个 USD 档位；threshold_usd_minor 以美分存储。
message CumulativeRechargeRewardTier {
  int64 tier_id = 1;
  string tier_code = 2;
  string tier_name = 3;
  int64 threshold_usd_minor = 4;
  int64 resource_group_id = 5;
  string status = 6;
  int32 sort_order = 7;
  int64 created_at_ms = 8;
  int64 updated_at_ms = 9;
}

// CumulativeRechargeRewardConfig 是当前 App 的累充奖励配置。
message CumulativeRechargeRewardConfig {
  string app_code = 1;
  bool enabled = 2;
  repeated CumulativeRechargeRewardTier tiers = 3;
  int64 updated_by_admin_id = 4;
  int64 created_at_ms = 5;
  int64 updated_at_ms = 6;
}

// CumulativeRechargeRewardGrant 是用户在一个 UTC 自然周内达成某个档位后的发放事实。
message CumulativeRechargeRewardGrant {
  string grant_id = 1;
  string app_code = 2;
  string cycle_key = 3;
  int64 user_id = 4;
  string event_id = 5;
  string transaction_id = 6;
  string command_id = 7;
  int64 tier_id = 8;
  string tier_code = 9;
  int64 threshold_usd_minor = 10;
  int64 resource_group_id = 11;
  int64 reached_usd_minor = 12;
  int64 qualifying_usd_minor = 13;
  int64 recharge_coin_amount = 14;
  string recharge_type = 15;
  string status = 16;
  string wallet_command_id = 17;
  string wallet_grant_id = 18;
  string failure_reason = 19;
  int64 granted_at_ms = 20;
  int64 created_at_ms = 21;
  int64 updated_at_ms = 22;
}

// CumulativeRechargeRewardProgress 是用户在当前 UTC 周期内的累充累计投影。
message CumulativeRechargeRewardProgress {
  string app_code = 1;
  string cycle_key = 2;
  int64 user_id = 3;
  int64 total_usd_minor = 4;
  int64 total_coin_amount = 5;
  int64 first_recharged_at_ms = 6;
  int64 last_recharged_at_ms = 7;
  int64 updated_at_ms = 8;
}

// CumulativeRechargeRewardStatus 是 App 累充奖励 H5 可直接展示的当前状态。
message CumulativeRechargeRewardStatus {
  CumulativeRechargeRewardConfig config = 1;
  CumulativeRechargeRewardProgress progress = 2;
  repeated CumulativeRechargeRewardGrant grants = 3;
  string cycle_key = 4;
  int64 period_start_ms = 5;
  int64 period_end_ms = 6;
  int64 server_time_ms = 7;
}

message GetCumulativeRechargeRewardStatusRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
}

message GetCumulativeRechargeRewardStatusResponse {
  CumulativeRechargeRewardStatus status = 1;
}

// ConsumeCumulativeRechargeRewardRequest 是 wallet 充值事实消费入口；所有成功充值都会按 UTC 周期累计。
message ConsumeCumulativeRechargeRewardRequest {
  RequestMeta meta = 1;
  string event_id = 2;
  string transaction_id = 3;
  string command_id = 4;
  int64 user_id = 5;
  int64 recharge_coin_amount = 6;
  int64 recharge_sequence = 7;
  string recharge_type = 8;
  int64 qualifying_usd_minor = 9;
  string payload_json = 10;
  int64 occurred_at_ms = 11;
}

message ConsumeCumulativeRechargeRewardResponse {
  repeated CumulativeRechargeRewardGrant grants = 1;
  bool consumed = 2;
  string reason = 3;
}

message GetCumulativeRechargeRewardConfigRequest {
  RequestMeta meta = 1;
}

message GetCumulativeRechargeRewardConfigResponse {
  CumulativeRechargeRewardConfig config = 1;
}

message UpdateCumulativeRechargeRewardConfigRequest {
  RequestMeta meta = 1;
  bool enabled = 2;
  repeated CumulativeRechargeRewardTier tiers = 3;
  int64 operator_admin_id = 4;
}

message UpdateCumulativeRechargeRewardConfigResponse {
  CumulativeRechargeRewardConfig config = 1;
}

message ListCumulativeRechargeRewardGrantsRequest {
  RequestMeta meta = 1;
  string status = 2;
  int64 user_id = 3;
  string cycle_key = 4;
  int32 page = 5;
  int32 page_size = 6;
}

message ListCumulativeRechargeRewardGrantsResponse {
  repeated CumulativeRechargeRewardGrant grants = 1;
  int64 total = 2;
}

// RoomTurnoverRewardTier 是房间流水奖励的单个档位；达到 threshold_coin_spent 后可命中奖励。
message RoomTurnoverRewardTier {
  int64 tier_id = 1;
  string tier_code = 2;
  string tier_name = 3;
  int64 threshold_coin_spent = 4;
  int64 reward_coin_amount = 5;
  string status = 6;
  int32 sort_order = 7;
  int64 created_at_ms = 8;
  int64 updated_at_ms = 9;
}

// RoomTurnoverRewardConfig 是当前 App 的房间流水奖励配置；结算只命中最高有效档。
message RoomTurnoverRewardConfig {
  string app_code = 1;
  bool enabled = 2;
  repeated RoomTurnoverRewardTier tiers = 3;
  int64 updated_by_admin_id = 4;
  int64 created_at_ms = 5;
  int64 updated_at_ms = 6;
}

// RoomTurnoverRewardSettlement 是某个房间单个 UTC 周期的结算事实。
message RoomTurnoverRewardSettlement {
  string settlement_id = 1;
  string app_code = 2;
  string room_id = 3;
  int64 owner_user_id = 4;
  int64 period_start_ms = 5;
  int64 period_end_ms = 6;
  int64 coin_spent = 7;
  int64 tier_id = 8;
  string tier_code = 9;
  int64 threshold_coin_spent = 10;
  int64 reward_coin_amount = 11;
  string status = 12;
  string wallet_command_id = 13;
  string wallet_transaction_id = 14;
  string failure_reason = 15;
  int64 settled_at_ms = 16;
  int64 created_at_ms = 17;
  int64 updated_at_ms = 18;
}

// RoomTurnoverRewardStatus 给 App H5 返回当前 UTC 周期、房间流水、预计奖励和上一期结算。
message RoomTurnoverRewardStatus {
  RoomTurnoverRewardConfig config = 1;
  string room_id = 2;
  int64 owner_user_id = 3;
  int64 period_start_ms = 4;
  int64 period_end_ms = 5;
  int64 current_coin_spent = 6;
  int64 expected_reward_coin_amount = 7;
  RoomTurnoverRewardTier matched_tier = 8;
  RoomTurnoverRewardSettlement latest_settlement = 9;
  int64 server_time_ms = 10;
}

message GetRoomTurnoverRewardStatusRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string room_id = 3;
  int64 owner_user_id = 4;
}

message GetRoomTurnoverRewardStatusResponse {
  RoomTurnoverRewardStatus status = 1;
}

message GetRoomTurnoverRewardConfigRequest {
  RequestMeta meta = 1;
}

message GetRoomTurnoverRewardConfigResponse {
  RoomTurnoverRewardConfig config = 1;
}

message UpdateRoomTurnoverRewardConfigRequest {
  RequestMeta meta = 1;
  bool enabled = 2;
  repeated RoomTurnoverRewardTier tiers = 3;
  int64 operator_admin_id = 4;
}

message UpdateRoomTurnoverRewardConfigResponse {
  RoomTurnoverRewardConfig config = 1;
}

message ListRoomTurnoverRewardSettlementsRequest {
  RequestMeta meta = 1;
  string status = 2;
  string room_id = 3;
  int64 owner_user_id = 4;
  int64 period_start_ms = 5;
  int32 page = 6;
  int32 page_size = 7;
}

message ListRoomTurnoverRewardSettlementsResponse {
  repeated RoomTurnoverRewardSettlement settlements = 1;
  int64 total = 2;
}

message RetryRoomTurnoverRewardSettlementRequest {
  RequestMeta meta = 1;
  string settlement_id = 2;
  int64 operator_admin_id = 3;
}

message RetryRoomTurnoverRewardSettlementResponse {
  RoomTurnoverRewardSettlement settlement = 1;
}

// SevenDayCheckInReward 是七日签到配置中某一天的资源组奖励。
message SevenDayCheckInReward {
  int32 day_index = 1;
  int64 resource_group_id = 2;
}

// SevenDayCheckInConfig 是当前 App 的七日签到配置；资源组内容仍由 wallet-service 拥有。
message SevenDayCheckInConfig {
  string app_code = 1;
  bool enabled = 2;
  int64 config_version = 3;
  repeated SevenDayCheckInReward rewards = 4;
  int64 updated_by_admin_id = 5;
  int64 created_at_ms = 6;
  int64 updated_at_ms = 7;
}

// SevenDayCheckInRewardStatus 是 App 面板中某一天奖励的用户侧状态。
message SevenDayCheckInRewardStatus {
  int32 day_index = 1;
  int64 resource_group_id = 2;
  string status = 3;
  string claim_id = 4;
  string wallet_grant_id = 5;
  int64 granted_at_ms = 6;
}

message GetSevenDayCheckInStatusRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
}

message GetSevenDayCheckInStatusResponse {
  bool enabled = 1;
  bool can_sign = 2;
  string reason = 3;
  int64 cycle_no = 4;
  int32 current_day_index = 5;
  int32 next_day_index = 6;
  string checkin_day = 7;
  string last_checkin_day = 8;
  int64 config_version = 9;
  repeated SevenDayCheckInRewardStatus rewards = 10;
  int64 server_time_ms = 11;
  int64 next_refresh_at_ms = 12;
}

message SignSevenDayCheckInRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string command_id = 3;
}

message SignSevenDayCheckInResponse {
  string claim_id = 1;
  int64 cycle_no = 2;
  string checkin_day = 3;
  int32 day_index = 4;
  int64 resource_group_id = 5;
  string status = 6;
  string wallet_grant_id = 7;
  int64 granted_at_ms = 8;
  int64 server_time_ms = 9;
}

message GetSevenDayCheckInConfigRequest {
  RequestMeta meta = 1;
}

message GetSevenDayCheckInConfigResponse {
  SevenDayCheckInConfig config = 1;
}

message UpdateSevenDayCheckInConfigRequest {
  RequestMeta meta = 1;
  bool enabled = 2;
  repeated SevenDayCheckInReward rewards = 3;
  int64 operator_admin_id = 4;
}

message UpdateSevenDayCheckInConfigResponse {
  SevenDayCheckInConfig config = 1;
}

// SevenDayCheckInClaim 是后台领取记录页使用的签到和资源组发放事实。
message SevenDayCheckInClaim {
  string claim_id = 1;
  string command_id = 2;
  int64 user_id = 3;
  int64 cycle_no = 4;
  string checkin_day = 5;
  int32 day_index = 6;
  int64 config_version = 7;
  int64 resource_group_id = 8;
  string wallet_command_id = 9;
  string wallet_grant_id = 10;
  string status = 11;
  string failure_reason = 12;
  int64 signed_at_ms = 13;
  int64 granted_at_ms = 14;
  int64 created_at_ms = 15;
  int64 updated_at_ms = 16;
}

message ListSevenDayCheckInClaimsRequest {
  RequestMeta meta = 1;
  string status = 2;
  int64 user_id = 3;
  string checkin_day = 4;
  int32 day_index = 5;
  int32 page = 6;
  int32 page_size = 7;
}

message ListSevenDayCheckInClaimsResponse {
  repeated SevenDayCheckInClaim claims = 1;
  int64 total = 2;
}

// LevelTrack 是等级体系的一条成长轨道，例如 wealth/game/charm。
message LevelTrack {
  string track = 1;
  string name = 2;
  string status = 3;
  int32 sort_order = 4;
  string display_config_json = 5;
  int64 created_at_ms = 6;
  int64 updated_at_ms = 7;
}

// LevelRule 是某条轨道的单级阈值和可选奖励配置。
message LevelRule {
  string track = 1;
  int32 level = 2;
  int64 required_value = 3;
  string name = 4;
  string status = 5;
  int64 reward_resource_group_id = 6;
  int32 sort_order = 7;
  string display_config_json = 8;
  int64 created_by_admin_id = 9;
  int64 updated_by_admin_id = 10;
  int64 created_at_ms = 11;
  int64 updated_at_ms = 12;
}

// LevelTier 是等级段展示和等级段奖励配置，例如 1-10 或 11-20。
message LevelTier {
  int64 tier_id = 1;
  string track = 2;
  int32 min_level = 3;
  int32 max_level = 4;
  string name = 5;
  int64 display_avatar_frame_resource_id = 6;
  int64 display_badge_resource_id = 7;
  int64 reward_resource_group_id = 8;
  string status = 9;
  string display_config_json = 10;
  int64 created_by_admin_id = 11;
  int64 updated_by_admin_id = 12;
  int64 created_at_ms = 13;
  int64 updated_at_ms = 14;
}

// LevelTrackOverview 是 App 等级总览里的单轨道进度。
message LevelTrackOverview {
  string track = 1;
  string name = 2;
  int32 level = 3;
  int64 tier_id = 4;
  int64 total_value = 5;
  int64 current_level_required_value = 6;
  int32 next_level = 7;
  int64 next_level_required_value = 8;
  int64 display_avatar_frame_resource_id = 9;
  int64 display_badge_resource_id = 10;
  int64 reward_pending_count = 11;
  int32 sort_order = 12;
  int32 display_badge_source_level = 13;
}

message GetMyLevelOverviewRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
}

message GetMyLevelOverviewResponse {
  repeated LevelTrackOverview tracks = 1;
  int64 server_time_ms = 2;
}

message GetLevelTrackRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string track = 3;
}

message GetLevelTrackResponse {
  LevelTrackOverview overview = 1;
  repeated LevelRule rules = 2;
  repeated LevelTier tiers = 3;
  int64 server_time_ms = 4;
}

// LevelDisplayTrackProfile 是资料卡和房间展示使用的单轨道等级投影。
message LevelDisplayTrackProfile {
  string track = 1;
  int32 level = 2;
  int64 tier_id = 3;
  int64 avatar_frame_resource_id = 4;
  int64 badge_resource_id = 5;
  int32 badge_source_level = 6;
  int64 updated_at_ms = 7;
}

// UserLevelDisplayProfile 固定返回财富、游戏、魅力三条轨道，避免客户端按数组猜槽位。
message UserLevelDisplayProfile {
  int64 user_id = 1;
  LevelDisplayTrackProfile wealth = 2;
  LevelDisplayTrackProfile game = 3;
  LevelDisplayTrackProfile charm = 4;
}

message BatchGetUserLevelDisplayProfilesRequest {
  RequestMeta meta = 1;
  repeated int64 user_ids = 2;
}

message BatchGetUserLevelDisplayProfilesResponse {
  repeated UserLevelDisplayProfile profiles = 1;
  int64 server_time_ms = 2;
}

// LevelRewardJob 是等级或等级段奖励的发放状态。
message LevelRewardJob {
  string reward_job_id = 1;
  int64 user_id = 2;
  string track = 3;
  string reward_source_type = 4;
  string reward_source_id = 5;
  int64 resource_group_id = 6;
  string wallet_command_id = 7;
  string wallet_grant_id = 8;
  string status = 9;
  int32 attempt_count = 10;
  string failure_reason = 11;
  int64 created_at_ms = 12;
  int64 updated_at_ms = 13;
}

message ListLevelRewardsRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string track = 3;
  string status = 4;
  int32 page = 5;
  int32 page_size = 6;
}

message ListLevelRewardsResponse {
  repeated LevelRewardJob rewards = 1;
  int64 total = 2;
}

// ConsumeLevelEventRequest 是内部事件 relay 投递给等级系统的幂等增量。
message ConsumeLevelEventRequest {
  RequestMeta meta = 1;
  string event_id = 2;
  string source_event_id = 3;
  string source_service = 4;
  string source_event_type = 5;
  int64 user_id = 6;
  string track = 7;
  string metric_type = 8;
  int64 value_delta = 9;
  int64 occurred_at_ms = 10;
  string dimensions_json = 11;
}

message ConsumeLevelEventResponse {
  string event_id = 1;
  string status = 2;
  bool level_changed = 3;
  int32 previous_level = 4;
  int32 new_level = 5;
  int64 reward_job_count = 6;
}

message SetUserLevelRequest {
  RequestMeta meta = 1;
  string command_id = 2;
  int64 user_id = 3;
  string track = 4;
  int32 level = 5;
  int64 operator_user_id = 6;
  string reason = 7;
}

message SetUserLevelResponse {
  string event_id = 1;
  string status = 2;
  string track = 3;
  int32 previous_level = 4;
  int32 new_level = 5;
  int64 total_value = 6;
  int64 reward_job_count = 7;
  int64 server_time_ms = 8;
}

message RegistrationLevelBadgeGrant {
  string track = 1;
  int32 level = 2;
  int64 resource_id = 3;
  string grant_id = 4;
}

message IssueRegistrationLevelBadgesRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string command_id = 3;
}

message IssueRegistrationLevelBadgesResponse {
  repeated RegistrationLevelBadgeGrant grants = 1;
  int64 server_time_ms = 2;
}

message UpsertLevelTrackRequest {
  RequestMeta meta = 1;
  string track = 2;
  string name = 3;
  string status = 4;
  int32 sort_order = 5;
  string display_config_json = 6;
}

message UpsertLevelTrackResponse {
  LevelTrack track = 1;
  bool created = 2;
}

message UpsertLevelRuleRequest {
  RequestMeta meta = 1;
  string track = 2;
  int32 level = 3;
  int64 required_value = 4;
  string name = 5;
  string status = 6;
  int64 reward_resource_group_id = 7;
  int32 sort_order = 8;
  string display_config_json = 9;
  int64 operator_admin_id = 10;
}

message UpsertLevelRuleResponse {
  LevelRule rule = 1;
  bool created = 2;
}

message UpsertLevelTierRequest {
  RequestMeta meta = 1;
  int64 tier_id = 2;
  string track = 3;
  int32 min_level = 4;
  int32 max_level = 5;
  string name = 6;
  int64 display_avatar_frame_resource_id = 7;
  int64 display_badge_resource_id = 8;
  int64 reward_resource_group_id = 9;
  string status = 10;
  string display_config_json = 11;
  int64 operator_admin_id = 12;
}

message UpsertLevelTierResponse {
  LevelTier tier = 1;
  bool created = 2;
}

// ListLevelConfigRequest 是后台等级配置页的配置读取请求；不绑定具体用户进度。
message ListLevelConfigRequest {
  RequestMeta meta = 1;
  string track = 2;
  string status = 3;
}

message ListLevelConfigResponse {
  repeated LevelTrack tracks = 1;
  repeated LevelRule rules = 2;
  repeated LevelTier tiers = 3;
  int64 server_time_ms = 4;
}

message AchievementCondition {
  string condition_id = 1;
  string achievement_id = 2;
  int64 version = 3;
  string metric_type = 4;
  int64 target_value = 5;
  string target_unit = 6;
  string dimension_filter_json = 7;
}

message AchievementDefinition {
  string achievement_id = 1;
  string collection_id = 2;
  string collection_type = 3;
  string achievement_type = 4;
  string title = 5;
  string description = 6;
  string status = 7;
  int64 version = 8;
  int64 primary_badge_resource_id = 9;
  int64 reward_resource_group_id = 10;
  string auto_pin_policy = 11;
  bool honor_visibility = 12;
  int64 effective_from_ms = 13;
  int64 effective_to_ms = 14;
  int32 sort_order = 15;
  string display_config_json = 16;
  int64 created_by_admin_id = 17;
  int64 updated_by_admin_id = 18;
  int64 created_at_ms = 19;
  int64 updated_at_ms = 20;
  repeated AchievementCondition conditions = 21;
}

message UserAchievement {
  AchievementDefinition definition = 1;
  string cycle_key = 2;
  int64 progress_value = 3;
  int64 target_value = 4;
  string user_status = 5;
  int64 unlocked_at_ms = 6;
  string reward_status = 7;
}

message ListAchievementsRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string collection_type = 3;
  string collection_id = 4;
  int32 page = 5;
  int32 page_size = 6;
}

message ListAchievementsResponse {
  repeated UserAchievement achievements = 1;
  int64 total = 2;
  int64 server_time_ms = 3;
}

message ConsumeAchievementEventRequest {
  RequestMeta meta = 1;
  string event_id = 2;
  string event_type = 3;
  string source_service = 4;
  int64 user_id = 5;
  string metric_type = 6;
  int64 value = 7;
  int64 occurred_at_ms = 8;
  string dimensions_json = 9;
}

message ConsumeAchievementEventResponse {
  string event_id = 1;
  string status = 2;
  int32 matched_achievement_count = 3;
  int32 unlocked_achievement_count = 4;
  int64 reward_job_count = 5;
}

message BadgeDisplayItem {
  string slot = 1;
  int32 position = 2;
  string badge_form = 3;
  int64 resource_id = 4;
  string entitlement_id = 5;
  string source_type = 6;
  string source_id = 7;
  string pin_mode = 8;
  int64 updated_at_ms = 9;
}

message ListMyBadgesRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
}

message ListMyBadgesResponse {
  repeated BadgeDisplayItem strip_badges = 1;
  repeated BadgeDisplayItem profile_tile_badges = 2;
  repeated BadgeDisplayItem honor_badges = 3;
  int64 server_time_ms = 4;
}

message SetBadgeDisplayRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string slot = 3;
  repeated BadgeDisplayItem items = 4;
  string command_id = 5;
}

message SetBadgeDisplayResponse {
  ListMyBadgesResponse profile = 1;
}

message UpsertAchievementDefinitionRequest {
  RequestMeta meta = 1;
  string achievement_id = 2;
  string collection_id = 3;
  string collection_type = 4;
  string achievement_type = 5;
  string title = 6;
  string description = 7;
  string status = 8;
  int64 primary_badge_resource_id = 9;
  int64 reward_resource_group_id = 10;
  string auto_pin_policy = 11;
  bool honor_visibility = 12;
  int64 effective_from_ms = 13;
  int64 effective_to_ms = 14;
  int32 sort_order = 15;
  string display_config_json = 16;
  int64 operator_admin_id = 17;
  repeated AchievementCondition conditions = 18;
}

message UpsertAchievementDefinitionResponse {
  AchievementDefinition achievement = 1;
  bool created = 2;
}

message LuckyGiftMeta {
  RequestMeta meta = 1;
  string command_id = 2;
  int64 user_id = 3;
  string device_id = 4;
  string room_id = 5;
  string anchor_id = 6;
  string gift_id = 7;
  int64 coin_spent = 8;
  int64 paid_at_ms = 9;
  string pool_id = 10;
  int64 target_user_id = 11;
  int32 gift_count = 12;
  // visible_region_id 来自 room-service 的房间可见区域，用于中奖后的区域 IM 飘屏。
  int64 visible_region_id = 13;
}

message LuckyGiftTier {
  string pool = 1;
  string tier_id = 2;
  int64 reward_coins = 3;
  int64 weight = 4;
  bool high_water_only = 5;
  bool enabled = 6;
  int64 multiplier_ppm = 7;
}

message LuckyGiftConfig {
  string app_code = 1;
  string gift_id = 2;
  bool enabled = 3;
  int64 rule_version = 4;
  int64 gift_price = 5;
  int64 target_rtp_ppm = 6;
  int64 pool_rate_ppm = 7;
  int64 global_window_draws = 8;
  int64 gift_window_draws = 9;
  int64 novice_draw_limit = 10;
  int64 intermediate_draw_limit = 11;
  int64 high_multiplier = 12;
  int64 high_water_pool_multiple = 13;
  int64 platform_pool_weight_ppm = 14;
  int64 room_pool_weight_ppm = 15;
  int64 gift_pool_weight_ppm = 16;
  int64 initial_platform_pool = 17;
  int64 initial_gift_pool = 18;
  int64 initial_room_pool = 19;
  int64 platform_reserve = 20;
  int64 gift_reserve = 21;
  int64 room_reserve = 22;
  int64 max_single_payout = 23;
  int64 user_hourly_payout_cap = 24;
  int64 user_daily_payout_cap = 25;
  int64 device_daily_payout_cap = 26;
  int64 room_hourly_payout_cap = 27;
  int64 anchor_daily_payout_cap = 28;
  int64 room_atmosphere_rate_ppm = 29;
  int64 room_atmosphere_initial = 30;
  int64 room_atmosphere_reserve = 31;
  int64 activity_budget = 32;
  int64 activity_daily_limit = 33;
  bool large_tier_enabled = 34;
  repeated LuckyGiftTier tiers = 35;
  int64 updated_by_admin_id = 36;
  int64 created_at_ms = 37;
  int64 updated_at_ms = 38;
  string pool_id = 39;
  repeated int64 multiplier_ppms = 40;
}

message LuckyGiftRuleTier {
  string stage = 1;
  string tier_id = 2;
  int64 multiplier_ppm = 3;
  int64 base_weight_ppm = 4;
  string reward_source = 5;
  bool high_water_only = 6;
  string broadcast_level = 7;
  bool enabled = 8;
}

message LuckyGiftRuleStage {
  string stage = 1;
  repeated LuckyGiftRuleTier tiers = 2;
}

message LuckyGiftRuleConfig {
  string app_code = 1;
  string pool_id = 2;
  int64 rule_version = 3;
  bool enabled = 4;
  int64 target_rtp_ppm = 5;
  int64 pool_rate_ppm = 6;
  int64 settlement_window_wager = 7;
  int64 control_band_ppm = 8;
  int64 gift_price_reference = 9;
  int64 novice_max_equivalent_draws = 10;
  int64 normal_max_equivalent_draws = 11;
  int64 effective_from_ms = 12;
  int64 created_by_admin_id = 13;
  int64 created_at_ms = 14;
  int64 max_single_payout = 15;
  int64 user_hourly_payout_cap = 16;
  int64 user_daily_payout_cap = 17;
  int64 device_daily_payout_cap = 18;
  int64 room_hourly_payout_cap = 19;
  int64 anchor_daily_payout_cap = 20;
  repeated LuckyGiftRuleStage stages = 21;
}

message CheckLuckyGiftRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string room_id = 3;
  string gift_id = 4;
  string pool_id = 5;
}

message CheckLuckyGiftResponse {
  bool enabled = 1;
  string reason = 2;
  string gift_id = 3;
  int64 gift_price = 4;
  int64 rule_version = 5;
  int64 target_rtp_ppm = 6;
  string experience_pool = 7;
  string pool_id = 8;
}

message LuckyGiftDrawResult {
  string draw_id = 1;
  string command_id = 2;
  string gift_id = 3;
  int64 rule_version = 4;
  string experience_pool = 5;
  string selected_tier_id = 6;
  int64 base_reward_coins = 7;
  int64 room_atmosphere_reward_coins = 8;
  int64 activity_subsidy_coins = 9;
  int64 effective_reward_coins = 10;
  string budget_sources_json = 11;
  string reward_status = 12;
  int64 rtp_window_index = 13;
  int64 gift_rtp_window_index = 14;
  int64 global_base_rtp_ppm = 15;
  int64 gift_base_rtp_ppm = 16;
  bool stage_feedback = 17;
  bool high_multiplier = 18;
  int64 created_at_ms = 19;
  string pool_id = 20;
  int64 multiplier_ppm = 21;
  string wallet_transaction_id = 22;
  int64 coin_balance_after = 23;
}

message ExecuteLuckyGiftDrawRequest {
  LuckyGiftMeta lucky_gift = 1;
}

message ExecuteLuckyGiftDrawResponse {
  LuckyGiftDrawResult result = 1;
}

message GetLuckyGiftConfigRequest {
  RequestMeta meta = 1;
  string gift_id = 2;
  string pool_id = 3;
}

message GetLuckyGiftConfigResponse {
  LuckyGiftRuleConfig config = 1;
}

message UpsertLuckyGiftConfigRequest {
  RequestMeta meta = 1;
  LuckyGiftRuleConfig config = 2;
  int64 operator_admin_id = 3;
}

message UpsertLuckyGiftConfigResponse {
  LuckyGiftRuleConfig config = 1;
}

message ListLuckyGiftConfigsRequest {
  RequestMeta meta = 1;
}

message ListLuckyGiftConfigsResponse {
  repeated LuckyGiftRuleConfig configs = 1;
}

message ListLuckyGiftDrawsRequest {
  RequestMeta meta = 1;
  string gift_id = 2;
  int64 user_id = 3;
  string room_id = 4;
  string status = 5;
  int32 page = 6;
  int32 page_size = 7;
  string pool_id = 8;
}

message ListLuckyGiftDrawsResponse {
  repeated LuckyGiftDrawResult draws = 1;
  int64 total = 2;
}

message LuckyGiftDrawSummary {
  string pool_id = 1;
  int64 total_draws = 2;
  int64 unique_users = 3;
  int64 unique_rooms = 4;
  int64 total_spent_coins = 5;
  int64 total_reward_coins = 6;
  int64 base_reward_coins = 7;
  int64 room_atmosphere_reward_coins = 8;
  int64 activity_subsidy_coins = 9;
  int64 actual_rtp_ppm = 10;
  int64 pending_draws = 11;
  int64 granted_draws = 12;
  int64 failed_draws = 13;
}

message GetLuckyGiftDrawSummaryRequest {
  RequestMeta meta = 1;
  string gift_id = 2;
  int64 user_id = 3;
  string room_id = 4;
  string status = 5;
  string pool_id = 6;
}

message GetLuckyGiftDrawSummaryResponse {
  LuckyGiftDrawSummary summary = 1;
}

// WeeklyStarGift 是周星周期内参与积分的指定礼物。
message WeeklyStarGift {
  string gift_id = 1;
  int32 sort_order = 2;
}

// WeeklyStarReward 是周星 Top 排名对应的资源组奖励。
message WeeklyStarReward {
  int32 rank_no = 1;
  int64 resource_group_id = 2;
}

// WeeklyStarCycle 是一个按 UTC epoch ms 生效的周星配置周期。
message WeeklyStarCycle {
  string cycle_id = 1;
  string activity_code = 2;
  int64 region_id = 3;
  string title = 4;
  string status = 5;
  int64 start_ms = 6;
  int64 end_ms = 7;
  repeated WeeklyStarGift gifts = 8;
  repeated WeeklyStarReward rewards = 9;
  int64 created_by_admin_id = 10;
  int64 updated_by_admin_id = 11;
  int64 settled_at_ms = 12;
  int64 created_at_ms = 13;
  int64 updated_at_ms = 14;
  string app_code = 15;
}

// WeeklyStarLeaderboardEntry 是一个周期内用户维度的积分排名。
message WeeklyStarLeaderboardEntry {
  int32 rank_no = 1;
  int64 user_id = 2;
  int64 score = 3;
  int64 first_scored_at_ms = 4;
  int64 last_scored_at_ms = 5;
}

// WeeklyStarSettlement 是周期结束后 Top 奖励发放的幂等记录。
message WeeklyStarSettlement {
  string settlement_id = 1;
  string cycle_id = 2;
  int32 rank_no = 3;
  int64 user_id = 4;
  int64 score = 5;
  int64 resource_group_id = 6;
  string wallet_command_id = 7;
  string wallet_grant_id = 8;
  string status = 9;
  string failure_reason = 10;
  int32 attempt_count = 11;
  int64 created_at_ms = 12;
  int64 updated_at_ms = 13;
}

message ListWeeklyStarCyclesRequest {
  RequestMeta meta = 1;
  int64 region_id = 2;
  string status = 3;
  int64 start_ms = 4;
  int64 end_ms = 5;
  int32 page = 6;
  int32 page_size = 7;
}

message ListWeeklyStarCyclesResponse {
  repeated WeeklyStarCycle cycles = 1;
  int64 total = 2;
}

message GetWeeklyStarCycleRequest {
  RequestMeta meta = 1;
  string cycle_id = 2;
}

message GetWeeklyStarCycleResponse {
  WeeklyStarCycle cycle = 1;
}

message UpsertWeeklyStarCycleRequest {
  RequestMeta meta = 1;
  WeeklyStarCycle cycle = 2;
  int64 operator_admin_id = 3;
}

message UpsertWeeklyStarCycleResponse {
  WeeklyStarCycle cycle = 1;
  bool created = 2;
}

message SetWeeklyStarCycleStatusRequest {
  RequestMeta meta = 1;
  string cycle_id = 2;
  string status = 3;
  int64 operator_admin_id = 4;
}

message SetWeeklyStarCycleStatusResponse {
  WeeklyStarCycle cycle = 1;
}

message ListWeeklyStarLeaderboardRequest {
  RequestMeta meta = 1;
  string cycle_id = 2;
  int64 region_id = 3;
  int32 page_size = 4;
  string page_token = 5;
}

message ListWeeklyStarLeaderboardResponse {
  WeeklyStarCycle cycle = 1;
  repeated WeeklyStarLeaderboardEntry entries = 2;
  string next_page_token = 3;
  int64 total = 4;
}

message ListWeeklyStarSettlementsRequest {
  RequestMeta meta = 1;
  string cycle_id = 2;
}

message ListWeeklyStarSettlementsResponse {
  repeated WeeklyStarSettlement settlements = 1;
}

message GetWeeklyStarCurrentRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  int64 region_id = 3;
}

message GetWeeklyStarCurrentResponse {
  WeeklyStarCycle cycle = 1;
  repeated WeeklyStarLeaderboardEntry top_entries = 2;
  WeeklyStarLeaderboardEntry my_entry = 3;
  int64 server_time_ms = 4;
}

message ListWeeklyStarHistoryRequest {
  RequestMeta meta = 1;
  int64 region_id = 2;
  int32 limit = 3;
}

message WeeklyStarHistoryCycle {
  WeeklyStarCycle cycle = 1;
  repeated WeeklyStarLeaderboardEntry top_entries = 2;
}

message ListWeeklyStarHistoryResponse {
  repeated WeeklyStarHistoryCycle cycles = 1;
  int64 server_time_ms = 2;
}

// ActivityService 只暴露同步查询，不把事件消费伪装成 RPC。
service ActivityService {
  rpc PingActivity(PingActivityRequest) returns (PingActivityResponse);
  rpc GetActivityStatus(GetActivityStatusRequest) returns (GetActivityStatusResponse);
}

// MessageInboxService 拥有 App system/activity 个人 inbox 事实。
service MessageInboxService {
  rpc ListMessageTabs(ListMessageTabsRequest) returns (ListMessageTabsResponse);
  rpc ListInboxMessages(ListInboxMessagesRequest) returns (ListInboxMessagesResponse);
  rpc MarkInboxMessageRead(MarkInboxMessageReadRequest) returns (MarkInboxMessageReadResponse);
  rpc MarkInboxSectionRead(MarkInboxSectionReadRequest) returns (MarkInboxSectionReadResponse);
  rpc DeleteInboxMessage(DeleteInboxMessageRequest) returns (DeleteInboxMessageResponse);
  rpc CreateInboxMessage(CreateInboxMessageRequest) returns (CreateInboxMessageResponse);
  rpc CreateFanoutJob(CreateFanoutJobRequest) returns (CreateFanoutJobResponse);
}

// ActivityCronService 只给 cron-service 调用，活动和消息状态仍由 activity-service owner 修改。
service ActivityCronService {
  rpc ProcessMessageFanoutBatch(CronBatchRequest) returns (CronBatchResponse);
  rpc ProcessLevelRewardBatch(CronBatchRequest) returns (CronBatchResponse);
  rpc ProcessAchievementRewardBatch(CronBatchRequest) returns (CronBatchResponse);
  rpc ProcessRoomTurnoverRewardSettlementBatch(CronBatchRequest) returns (CronBatchResponse);
  rpc ProcessWeeklyStarSettlementBatch(CronBatchRequest) returns (CronBatchResponse);
}

// TaskService 拥有 App 任务查询、事件进度消费和领奖状态。
service TaskService {
  rpc ListUserTasks(ListUserTasksRequest) returns (ListUserTasksResponse);
  rpc ClaimTaskReward(ClaimTaskRewardRequest) returns (ClaimTaskRewardResponse);
  rpc ConsumeTaskEvent(ConsumeTaskEventRequest) returns (ConsumeTaskEventResponse);
}

// GrowthLevelService 拥有 App 等级查询和内部等级事件消费。
service GrowthLevelService {
  rpc GetMyLevelOverview(GetMyLevelOverviewRequest) returns (GetMyLevelOverviewResponse);
  rpc GetLevelTrack(GetLevelTrackRequest) returns (GetLevelTrackResponse);
  rpc BatchGetUserLevelDisplayProfiles(BatchGetUserLevelDisplayProfilesRequest) returns (BatchGetUserLevelDisplayProfilesResponse);
  rpc ListLevelRewards(ListLevelRewardsRequest) returns (ListLevelRewardsResponse);
  rpc ConsumeLevelEvent(ConsumeLevelEventRequest) returns (ConsumeLevelEventResponse);
  rpc SetUserLevel(SetUserLevelRequest) returns (SetUserLevelResponse);
  rpc IssueRegistrationLevelBadges(IssueRegistrationLevelBadgesRequest) returns (IssueRegistrationLevelBadgesResponse);
}

// AchievementService owns App achievement reads, badge display and internal achievement event consumption.
service AchievementService {
  rpc ListAchievements(ListAchievementsRequest) returns (ListAchievementsResponse);
  rpc ConsumeAchievementEvent(ConsumeAchievementEventRequest) returns (ConsumeAchievementEventResponse);
  rpc ListMyBadges(ListMyBadgesRequest) returns (ListMyBadgesResponse);
  rpc SetBadgeDisplay(SetBadgeDisplayRequest) returns (SetBadgeDisplayResponse);
}

// LuckyGiftService owns lucky gift rule checks and draw decisions after wallet debit succeeds.
service LuckyGiftService {
  rpc CheckLuckyGift(CheckLuckyGiftRequest) returns (CheckLuckyGiftResponse);
  rpc ExecuteLuckyGiftDraw(ExecuteLuckyGiftDrawRequest) returns (ExecuteLuckyGiftDrawResponse);
}

// RoomTurnoverRewardService owns App reads for the weekly room turnover reward activity.
service RoomTurnoverRewardService {
  rpc GetRoomTurnoverRewardStatus(GetRoomTurnoverRewardStatusRequest) returns (GetRoomTurnoverRewardStatusResponse);
}

// WeeklyStarService owns App reads for the weekly specified-gift score activity.
service WeeklyStarService {
  rpc GetWeeklyStarCurrent(GetWeeklyStarCurrentRequest) returns (GetWeeklyStarCurrentResponse);
  rpc ListWeeklyStarLeaderboard(ListWeeklyStarLeaderboardRequest) returns (ListWeeklyStarLeaderboardResponse);
  rpc ListWeeklyStarHistory(ListWeeklyStarHistoryRequest) returns (ListWeeklyStarHistoryResponse);
}

// BroadcastService owns server-side Tencent IM global/region broadcast delivery.
service BroadcastService {
  rpc EnsureBroadcastGroups(EnsureBroadcastGroupsRequest) returns (EnsureBroadcastGroupsResponse);
  rpc PublishRegionBroadcast(PublishRegionBroadcastRequest) returns (PublishBroadcastResponse);
  rpc PublishGlobalBroadcast(PublishGlobalBroadcastRequest) returns (PublishBroadcastResponse);
  rpc RemoveRegionBroadcastMember(RemoveRegionBroadcastMemberRequest) returns (RemoveRegionBroadcastMemberResponse);
  rpc ProcessBroadcastOutboxBatch(CronBatchRequest) returns (ProcessBroadcastOutboxBatchResponse);
}

// RoomEventConsumerService consumes room-service outbox facts without owning Room Cell state.
service RoomEventConsumerService {
  rpc ConsumeRoomEvent(ConsumeRoomEventRequest) returns (ConsumeRoomEventResponse);
}

// AdminTaskService 是后台活动管理访问 activity-service 的唯一任务配置入口。
service AdminTaskService {
  rpc ListTaskDefinitions(ListTaskDefinitionsRequest) returns (ListTaskDefinitionsResponse);
  rpc UpsertTaskDefinition(UpsertTaskDefinitionRequest) returns (UpsertTaskDefinitionResponse);
  rpc SetTaskDefinitionStatus(SetTaskDefinitionStatusRequest) returns (SetTaskDefinitionStatusResponse);
}

// RegistrationRewardService 拥有 App 查询和注册完成发放入口。
service RegistrationRewardService {
  rpc GetRegistrationRewardEligibility(GetRegistrationRewardEligibilityRequest) returns (GetRegistrationRewardEligibilityResponse);
  rpc IssueRegistrationReward(IssueRegistrationRewardRequest) returns (IssueRegistrationRewardResponse);
}

// AdminRegistrationRewardService 是后台活动管理访问注册奖励配置和领取记录的唯一入口。
service AdminRegistrationRewardService {
  rpc GetRegistrationRewardConfig(GetRegistrationRewardConfigRequest) returns (GetRegistrationRewardConfigResponse);
  rpc UpdateRegistrationRewardConfig(UpdateRegistrationRewardConfigRequest) returns (UpdateRegistrationRewardConfigResponse);
  rpc ListRegistrationRewardClaims(ListRegistrationRewardClaimsRequest) returns (ListRegistrationRewardClaimsResponse);
}

// FirstRechargeRewardService 拥有 App 首冲奖励查询和 wallet 充值事实消费入口。
service FirstRechargeRewardService {
  rpc GetFirstRechargeRewardStatus(GetFirstRechargeRewardStatusRequest) returns (GetFirstRechargeRewardStatusResponse);
  rpc ConsumeFirstRechargeReward(ConsumeFirstRechargeRewardRequest) returns (ConsumeFirstRechargeRewardResponse);
}

// AdminFirstRechargeRewardService 是后台活动管理访问首冲奖励配置和发放记录的唯一入口。
service AdminFirstRechargeRewardService {
  rpc GetFirstRechargeRewardConfig(GetFirstRechargeRewardConfigRequest) returns (GetFirstRechargeRewardConfigResponse);
  rpc UpdateFirstRechargeRewardConfig(UpdateFirstRechargeRewardConfigRequest) returns (UpdateFirstRechargeRewardConfigResponse);
  rpc ListFirstRechargeRewardClaims(ListFirstRechargeRewardClaimsRequest) returns (ListFirstRechargeRewardClaimsResponse);
}

// CumulativeRechargeRewardService 拥有 App 累充奖励查询和 wallet 充值事实消费入口。
service CumulativeRechargeRewardService {
  rpc GetCumulativeRechargeRewardStatus(GetCumulativeRechargeRewardStatusRequest) returns (GetCumulativeRechargeRewardStatusResponse);
  rpc ConsumeCumulativeRechargeReward(ConsumeCumulativeRechargeRewardRequest) returns (ConsumeCumulativeRechargeRewardResponse);
}

// AdminCumulativeRechargeRewardService 是后台活动管理访问累充奖励配置和发放记录的唯一入口。
service AdminCumulativeRechargeRewardService {
  rpc GetCumulativeRechargeRewardConfig(GetCumulativeRechargeRewardConfigRequest) returns (GetCumulativeRechargeRewardConfigResponse);
  rpc UpdateCumulativeRechargeRewardConfig(UpdateCumulativeRechargeRewardConfigRequest) returns (UpdateCumulativeRechargeRewardConfigResponse);
  rpc ListCumulativeRechargeRewardGrants(ListCumulativeRechargeRewardGrantsRequest) returns (ListCumulativeRechargeRewardGrantsResponse);
}

// AdminRoomTurnoverRewardService 是后台活动管理访问房间流水奖励配置和结算记录的唯一入口。
service AdminRoomTurnoverRewardService {
  rpc GetRoomTurnoverRewardConfig(GetRoomTurnoverRewardConfigRequest) returns (GetRoomTurnoverRewardConfigResponse);
  rpc UpdateRoomTurnoverRewardConfig(UpdateRoomTurnoverRewardConfigRequest) returns (UpdateRoomTurnoverRewardConfigResponse);
  rpc ListRoomTurnoverRewardSettlements(ListRoomTurnoverRewardSettlementsRequest) returns (ListRoomTurnoverRewardSettlementsResponse);
  rpc RetryRoomTurnoverRewardSettlement(RetryRoomTurnoverRewardSettlementRequest) returns (RetryRoomTurnoverRewardSettlementResponse);
}

// AdminWeeklyStarService 是后台活动管理访问周星周期、榜单和结算结果的唯一入口。
service AdminWeeklyStarService {
  rpc ListWeeklyStarCycles(ListWeeklyStarCyclesRequest) returns (ListWeeklyStarCyclesResponse);
  rpc CreateWeeklyStarCycle(UpsertWeeklyStarCycleRequest) returns (UpsertWeeklyStarCycleResponse);
  rpc GetWeeklyStarCycle(GetWeeklyStarCycleRequest) returns (GetWeeklyStarCycleResponse);
  rpc UpdateWeeklyStarCycle(UpsertWeeklyStarCycleRequest) returns (UpsertWeeklyStarCycleResponse);
  rpc SetWeeklyStarCycleStatus(SetWeeklyStarCycleStatusRequest) returns (SetWeeklyStarCycleStatusResponse);
  rpc ListWeeklyStarLeaderboard(ListWeeklyStarLeaderboardRequest) returns (ListWeeklyStarLeaderboardResponse);
  rpc ListWeeklyStarSettlements(ListWeeklyStarSettlementsRequest) returns (ListWeeklyStarSettlementsResponse);
}

// SevenDayCheckInService 拥有 App 七日签到查询和签到命令。
service SevenDayCheckInService {
  rpc GetSevenDayCheckInStatus(GetSevenDayCheckInStatusRequest) returns (GetSevenDayCheckInStatusResponse);
  rpc SignSevenDayCheckIn(SignSevenDayCheckInRequest) returns (SignSevenDayCheckInResponse);
}

// AdminSevenDayCheckInService 是后台活动管理访问七日签到配置和领取记录的唯一入口。
service AdminSevenDayCheckInService {
  rpc GetSevenDayCheckInConfig(GetSevenDayCheckInConfigRequest) returns (GetSevenDayCheckInConfigResponse);
  rpc UpdateSevenDayCheckInConfig(UpdateSevenDayCheckInConfigRequest) returns (UpdateSevenDayCheckInConfigResponse);
  rpc ListSevenDayCheckInClaims(ListSevenDayCheckInClaimsRequest) returns (ListSevenDayCheckInClaimsResponse);
}

// AdminGrowthLevelService 是后台等级配置访问 activity-service 的唯一入口。
service AdminGrowthLevelService {
  rpc ListLevelConfig(ListLevelConfigRequest) returns (ListLevelConfigResponse);
  rpc UpsertLevelTrack(UpsertLevelTrackRequest) returns (UpsertLevelTrackResponse);
  rpc UpsertLevelRule(UpsertLevelRuleRequest) returns (UpsertLevelRuleResponse);
  rpc UpsertLevelTier(UpsertLevelTierRequest) returns (UpsertLevelTierResponse);
}

// AdminAchievementService is the admin entry for achievement definitions.
service AdminAchievementService {
  rpc ListAchievementDefinitions(ListAchievementsRequest) returns (ListAchievementsResponse);
  rpc UpsertAchievementDefinition(UpsertAchievementDefinitionRequest) returns (UpsertAchievementDefinitionResponse);
}

// AdminLuckyGiftService is the admin entry for lucky gift rule versions and draw audit.
service AdminLuckyGiftService {
  rpc GetLuckyGiftConfig(GetLuckyGiftConfigRequest) returns (GetLuckyGiftConfigResponse);
  rpc UpsertLuckyGiftConfig(UpsertLuckyGiftConfigRequest) returns (UpsertLuckyGiftConfigResponse);
  rpc ListLuckyGiftConfigs(ListLuckyGiftConfigsRequest) returns (ListLuckyGiftConfigsResponse);
  rpc ListLuckyGiftDraws(ListLuckyGiftDrawsRequest) returns (ListLuckyGiftDrawsResponse);
  rpc GetLuckyGiftDrawSummary(GetLuckyGiftDrawSummaryRequest) returns (GetLuckyGiftDrawSummaryResponse);
}
