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;
  // image_urls 是同一通知卡片的有序图片列表；image_url 保留给旧客户端作为首图兼容字段。
  repeated string image_urls = 12;
  // reward_items 是活动发奖的有序结构化快照；客户端不解析 body/metadata_json 猜测数量和有效天数。
  repeated InboxRewardItem reward_items = 13;
  // actions 最多两个；每个按钮的文案、样式、API 和参数均由后端快照提供。
  repeated InboxAction actions = 14;
}

// 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;
  // image_urls 由 inbox owner 结构化保存，生产者不能要求客户端解析 metadata_json。
  repeated string image_urls = 22;
  // reward_items 与 image_urls 一样由 inbox owner 写入受控 metadata，避免扩表并保持强类型输出。
  repeated InboxRewardItem reward_items = 23;
  // actions 由 inbox owner 校验并写入 metadata JSON；客户端只消费强类型输出。
  repeated InboxAction actions = 24;
}

// 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;
}

// ActionConfirm 是 App C2C IM 操作按钮背后的后端确认事实。
message ActionConfirm {
  string confirm_id = 1;
  string business_type = 2;
  string business_subtype = 3;
  string business_id = 4;
  int64 sender_user_id = 5;
  int64 receiver_user_id = 6;
  string status = 7;
  string action = 8;
  int64 processed_at_ms = 9;
  int64 created_at_ms = 10;
  int64 updated_at_ms = 11;
}

message AcceptActionConfirmRequest {
  RequestMeta meta = 1;
  string confirm_id = 2;
  int64 actor_user_id = 3;
  string command_id = 4;
}

message AcceptActionConfirmResponse {
  ActionConfirm confirm = 1;
}

message RejectActionConfirmRequest {
  RequestMeta meta = 1;
  string confirm_id = 2;
  int64 actor_user_id = 3;
  string command_id = 4;
  string reason = 5;
}

message RejectActionConfirmResponse {
  ActionConfirm confirm = 1;
}

message BatchGetActionConfirmStatusRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  repeated string confirm_ids = 3;
}

message BatchGetActionConfirmStatusResponse {
  repeated ActionConfirm items = 1;
}

message ListConversationActionConfirmsRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  int64 peer_user_id = 3;
  int32 page_size = 4;
  string page_token = 5;
}

message ListConversationActionConfirmsResponse {
  repeated ActionConfirm items = 1;
  string next_page_token = 2;
}

// 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;
}

// TaskRewardItem 是任务保存时从 wallet 资源目录解析出的展示快照。
// resource 奖励只给客户端封面和资源语义；名称不进入任务 H5，避免运营改名影响任务卡片。
message TaskRewardItem {
  string item_type = 1;
  int64 resource_id = 2;
  string resource_type = 3;
  string cover_url = 4;
  int64 quantity = 5;
  int64 duration_ms = 6;
  string wallet_asset_type = 7;
  int64 wallet_asset_amount = 8;
}

// 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;
  string audience_type = 18;
  string icon_key = 19;
  string icon_url = 20;
  string action_type = 21;
  string action_param = 22;
  string action_payload_json = 23;
  string dimension_filter_json = 24;
  string reward_asset_type = 25;
  string reward_type = 26;
  int64 reward_resource_id = 27;
  int64 reward_resource_group_id = 28;
  int64 reward_quantity = 29;
  int64 reward_duration_ms = 30;
  repeated TaskRewardItem reward_items = 31;
}

// 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;
  string reward_asset_type = 10;
  string reward_type = 11;
  int64 reward_resource_id = 12;
  int64 reward_resource_group_id = 13;
  string wallet_resource_grant_id = 14;
  repeated TaskRewardItem reward_items = 15;
}

// 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;
  string dimensions_json = 9;
}

// 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;
}

// GameWinBroadcastConfig 是 activity-service 按 App 持有的游戏中奖飘屏策略。
// game-service 只发布已结算资金事实，不能读取或拥有这份展示配置。
message GameWinBroadcastConfig {
  bool enabled = 1;
  int64 min_win_coins = 2;
  int64 updated_by_admin_id = 3;
  int64 created_at_ms = 4;
  int64 updated_at_ms = 5;
}

message GetGameWinBroadcastConfigRequest {
  RequestMeta meta = 1;
}

message GetGameWinBroadcastConfigResponse {
  GameWinBroadcastConfig config = 1;
}

message UpdateGameWinBroadcastConfigRequest {
  RequestMeta meta = 1;
  bool enabled = 2;
  int64 min_win_coins = 3;
  int64 operator_admin_id = 4;
}

message UpdateGameWinBroadcastConfigResponse {
  GameWinBroadcastConfig config = 1;
}

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;
  string audience_type = 19;
  string icon_key = 20;
  string icon_url = 21;
  string action_type = 22;
  string action_param = 23;
  string action_payload_json = 24;
  string dimension_filter_json = 25;
  string reward_asset_type = 26;
  string reward_type = 27;
  int64 reward_resource_id = 28;
  int64 reward_resource_group_id = 29;
  int64 reward_quantity = 30;
  int64 reward_duration_ms = 31;
  repeated TaskRewardItem reward_items = 32;
}

// 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;
  string audience_type = 16;
  string icon_key = 17;
  string icon_url = 18;
  string action_type = 19;
  string action_param = 20;
  string action_payload_json = 21;
  string dimension_filter_json = 22;
  string reward_asset_type = 23;
  string reward_type = 24;
  int64 reward_resource_id = 25;
  int64 reward_resource_group_id = 26;
  int64 reward_quantity = 27;
  int64 reward_duration_ms = 28;
}

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;
}

// Deprecated: 任务奖励资产现在由每条 TaskDefinition.reward_asset_type 显式配置。
// 保留消息仅用于旧 Admin 客户端与新 Activity 服务滚动发布时的 wire 兼容。
message PublishTaskRewardPolicyRequest {
  option deprecated = true;

  RequestMeta meta = 1;
  string instance_code = 2;
  string template_code = 3;
  string template_version = 4;
  string status = 5;
  string reward_asset_type = 6;
  string rule_json = 7;
  int64 operator_admin_id = 8;
  int64 published_at_ms = 9;
}

// Deprecated: 服务端不再发布运行侧任务默认资产，调用会返回明确的已退役错误。
message PublishTaskRewardPolicyResponse {
  option deprecated = true;

  string app_code = 1;
  string instance_code = 2;
  string status = 3;
  string reward_asset_type = 4;
  int64 published_at_ms = 5;
}

// 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 是首冲奖励的一个 Google 商品档位；旧金币区间字段仅保留兼容。
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;
  int64 usd_minor_amount = 11;
  string google_product_id = 12;
  int32 discount_percent = 13;
}

// 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 是某个用户购买某个首充档位后的发奖事实；同一用户同一档位只处理一次。
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;
  int64 tier_usd_minor_amount = 20;
  string google_product_id = 21;
  int64 recharge_usd_minor = 22;
}

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

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

message GetFirstRechargeRewardStatusResponse {
  FirstRechargeRewardStatus status = 1;
}

// ConsumeFirstRechargeRewardRequest 是 wallet 充值事实消费入口；Google 商品 ID 命中档位后发奖。
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;
  int64 recharge_usd_minor = 10;
  string google_product_id = 11;
}

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;
}

// InviteActivityRewardTier 是邀请活动的金币奖励档位；recharge 使用充值门槛，valid_invite 使用有效邀请人数门槛。
message InviteActivityRewardTier {
  int64 tier_id = 1;
  string reward_type = 2;
  string tier_code = 3;
  string tier_name = 4;
  int64 threshold_coin_amount = 5;
  int64 threshold_valid_invite_count = 6;
  int64 reward_coin_amount = 7;
  string status = 8;
  int32 sort_order = 9;
  int64 created_at_ms = 10;
  int64 updated_at_ms = 11;
}

// InviteActivityRewardConfig 是当前 App 的邀请活动配置；关闭时保留档位但 App 不允许领取。
message InviteActivityRewardConfig {
  string app_code = 1;
  bool enabled = 2;
  repeated InviteActivityRewardTier tiers = 3;
  int64 updated_by_admin_id = 4;
  int64 created_at_ms = 5;
  int64 updated_at_ms = 6;
  int64 per_invite_inviter_reward_coin_amount = 7;
  int64 per_invite_invitee_reward_coin_amount = 8;
}

// InviteActivityRewardProgress 是邀请人在 UTC 自然月内的充值和有效邀请累计。
message InviteActivityRewardProgress {
  string app_code = 1;
  string cycle_key = 2;
  int64 user_id = 3;
  int64 total_recharge_coin_amount = 4;
  int64 valid_invite_count = 5;
  int64 claimed_reward_coin_amount = 6;
  int64 updated_at_ms = 7;
}

// InviteActivityRewardClaim 是用户点击领取后创建的钱包发奖事实。
message InviteActivityRewardClaim {
  string claim_id = 1;
  string app_code = 2;
  string cycle_key = 3;
  int64 user_id = 4;
  string reward_type = 5;
  string command_id = 6;
  int64 tier_id = 7;
  string tier_code = 8;
  string tier_name = 9;
  int64 threshold_coin_amount = 10;
  int64 threshold_valid_invite_count = 11;
  int64 reached_value = 12;
  int64 reward_coin_amount = 13;
  string status = 14;
  string wallet_command_id = 15;
  string wallet_transaction_id = 16;
  string failure_reason = 17;
  int64 granted_at_ms = 18;
  int64 created_at_ms = 19;
  int64 updated_at_ms = 20;
}

// InviteActivityRewardStatus 是 App 邀请奖励页可直接展示的当前周期状态。
message InviteActivityRewardStatus {
  InviteActivityRewardConfig config = 1;
  InviteActivityRewardProgress progress = 2;
  repeated InviteActivityRewardClaim claims = 3;
  string cycle_key = 4;
  int64 period_start_ms = 5;
  int64 period_end_ms = 6;
  int64 server_time_ms = 7;
}

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

message GetInviteActivityRewardStatusResponse {
  InviteActivityRewardStatus status = 1;
}

message ClaimInviteActivityRewardRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string reward_type = 3;
  int64 tier_id = 4;
  string command_id = 5;
}

message ClaimInviteActivityRewardResponse {
  InviteActivityRewardClaim claim = 1;
  InviteActivityRewardStatus status = 2;
}

// InviteActivityLeaderboardEntry 是邀请活动月榜的一行；用户资料由 gateway 出口补齐。
message InviteActivityLeaderboardEntry {
  int32 rank_no = 1;
  int64 user_id = 2;
  int64 valid_invite_count = 3;
  int64 total_recharge_coin_amount = 4;
}

message ListInviteActivityLeaderboardRequest {
  RequestMeta meta = 1;
  string cycle_key = 2;
  int32 page = 3;
  int32 page_size = 4;
}

message ListInviteActivityLeaderboardResponse {
  repeated InviteActivityLeaderboardEntry entries = 1;
  int64 total = 2;
  string cycle_key = 3;
  int64 server_time_ms = 4;
}

message GetInviteActivityRewardConfigRequest {
  RequestMeta meta = 1;
}

message GetInviteActivityRewardConfigResponse {
  InviteActivityRewardConfig config = 1;
}

message UpdateInviteActivityRewardConfigRequest {
  RequestMeta meta = 1;
  bool enabled = 2;
  repeated InviteActivityRewardTier tiers = 3;
  int64 operator_admin_id = 4;
  int64 per_invite_inviter_reward_coin_amount = 5;
  int64 per_invite_invitee_reward_coin_amount = 6;
}

message UpdateInviteActivityRewardConfigResponse {
  InviteActivityRewardConfig config = 1;
}

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

message ListInviteActivityRewardClaimsResponse {
  repeated InviteActivityRewardClaim claims = 1;
  int64 total = 2;
}

// InviteActivityRewardInviteeSummary 是后台邀请活动聚合行展开后的被邀请人明细。
message InviteActivityRewardInviteeSummary {
  int64 invited_user_id = 1;
  int64 recharge_coin_amount = 2;
  int64 invited_at_ms = 3;
}

// ListInviteActivityInviteesRequest 只允许查询鉴权用户自己的当前 UTC 月邀请明细。
message ListInviteActivityInviteesRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  int32 page = 3;
  int32 page_size = 4;
}

message ListInviteActivityInviteesResponse {
  repeated InviteActivityRewardInviteeSummary invitees = 1;
  int64 total = 2;
  int32 page = 3;
  int32 page_size = 4;
  string cycle_key = 5;
  int64 server_time_ms = 6;
}

// InviteActivityRewardSummary 是后台邀请活动列表的一行，按邀请人和周期聚合。
message InviteActivityRewardSummary {
  string app_code = 1;
  string cycle_key = 2;
  int64 user_id = 3;
  int64 invite_count = 4;
  int64 valid_invite_count = 5;
  int64 total_recharge_coin_amount = 6;
  int64 total_reward_coin_amount = 7;
  int64 updated_at_ms = 8;
  repeated InviteActivityRewardInviteeSummary invitees = 9;
}

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

message ListInviteActivityRewardSummariesResponse {
  repeated InviteActivityRewardSummary summaries = 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;
  // region_id=0 表示全区域默认配置；正数表示只覆盖对应区域。
  int64 region_id = 7;
}

// 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;
  // region_id 固化贡献事件发生时的房间可见区域；0 表示全区域可见房间。
  int64 region_id = 19;
}

// 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;
  int64 region_id = 5;
}

message GetRoomTurnoverRewardStatusResponse {
  RoomTurnoverRewardStatus status = 1;
}

message GetRoomTurnoverRewardConfigRequest {
  RequestMeta meta = 1;
  int64 region_id = 2;
}

message GetRoomTurnoverRewardConfigResponse {
  RoomTurnoverRewardConfig config = 1;
}

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

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;
  int64 region_id = 8;
}

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;
  string reward_origin = 14;
  string temporary_level_id = 15;
  int32 grant_generation = 16;
  int32 reward_level = 17;
  bool permanent = 18;
  int64 temporary_expires_at_ms = 19;
  string revoke_status = 20;
}

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;
}

// AdminLevelTrackProfile keeps the permanent account and the currently effective display overlay separate.
message AdminLevelTrackProfile {
  string track = 1;
  int32 real_level = 2;
  int64 real_total_value = 3;
  int32 display_level = 4;
  int64 display_value = 5;
  string temporary_level_id = 6;
  int32 temporary_target_level = 7;
  int64 started_at_ms = 8;
  int64 expires_at_ms = 9;
}

message AdminUserLevelProfile {
  int64 user_id = 1;
  repeated AdminLevelTrackProfile tracks = 2;
}

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

message BatchGetUserLevelAdminProfilesResponse {
  repeated AdminUserLevelProfile profiles = 1;
  int64 server_time_ms = 2;
}

// TemporaryLevelAdjustment is limited to wealth/charm; duration_days must be positive and level is 1..50.
message TemporaryLevelAdjustment {
  string track = 1;
  int32 level = 2;
  int32 duration_days = 3;
}

message AdjustTemporaryUserLevelsRequest {
  RequestMeta meta = 1;
  string command_id = 2;
  int64 user_id = 3;
  repeated TemporaryLevelAdjustment adjustments = 4;
  int64 operator_admin_id = 5;
  string reason = 6;
}

message AdjustTemporaryUserLevelsResponse {
  AdminUserLevelProfile profile = 1;
  int64 server_time_ms = 2;
}

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;
}

// BatchUpsertLevelConfigRequest 把同一次运营编辑中的规则和等级段合并成一个原子命令。
// rules/tiers 复用完整配置 DTO；服务端忽略其中审计和时间字段，统一使用外层操作人。
message BatchUpsertLevelConfigRequest {
  RequestMeta meta = 1;
  repeated LevelRule rules = 2;
  repeated LevelTier tiers = 3;
  int64 operator_admin_id = 4;
}

message BatchUpsertLevelConfigResponse {
  repeated LevelRule rules = 1;
  repeated LevelTier tiers = 2;
  int64 server_time_ms = 3;
}

// 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 DeleteAchievementDefinitionRequest {
  RequestMeta meta = 1;
  string achievement_id = 2;
  int64 operator_admin_id = 3;
}

message DeleteAchievementDefinitionResponse {
  AchievementDefinition achievement = 1;
}

message WheelPrizeTier {
  string tier_id = 1;
  string display_name = 2;
  string reward_type = 3;
  string reward_id = 4;
  int64 reward_count = 5;
  int64 reward_coins = 6;
  int64 rtp_value_coins = 7;
  int64 weight_ppm = 8;
  bool enabled = 9;
  string metadata_json = 10;
}

message WheelRuleConfig {
  string app_code = 1;
  string wheel_id = 2;
  int64 rule_version = 3;
  bool enabled = 4;
  int64 draw_price_coins = 5;
  int64 target_rtp_ppm = 6;
  int64 pool_rate_ppm = 7;
  int64 settlement_window_draws = 8;
  int64 initial_pool_coins = 9;
  int64 pool_reserve_coins = 10;
  int64 max_single_rtp_payout = 11;
  int64 effective_from_ms = 12;
  int64 created_by_admin_id = 13;
  int64 created_at_ms = 14;
  repeated WheelPrizeTier tiers = 15;
}

message WheelDrawMeta {
  RequestMeta meta = 1;
  string command_id = 2;
  string wheel_id = 3;
  int64 user_id = 4;
  string device_id = 5;
  int32 draw_count = 6;
  int64 coin_spent = 7;
  int64 paid_at_ms = 8;
  int64 visible_region_id = 9;
}

message WheelDrawResult {
  string draw_id = 1;
  repeated string draw_ids = 2;
  string command_id = 3;
  string wheel_id = 4;
  int64 rule_version = 5;
  string selected_tier_id = 6;
  string reward_type = 7;
  string reward_id = 8;
  int64 reward_count = 9;
  int64 reward_coins = 10;
  int64 rtp_value_coins = 11;
  string reward_status = 12;
  int64 rtp_window_index = 13;
  int64 actual_rtp_ppm = 14;
  int64 created_at_ms = 15;
  string wallet_transaction_id = 16;
  int64 coin_balance_after = 17;
  string metadata_json = 18;
  repeated WheelDrawReward rewards = 19;
}

message WheelDrawReward {
  string selected_tier_id = 1;
  string reward_type = 2;
  string reward_id = 3;
  int64 reward_count = 4;
  int64 reward_coins = 5;
  int64 rtp_value_coins = 6;
  string reward_status = 7;
  string metadata_json = 8;
}

message ExecuteWheelDrawRequest {
  WheelDrawMeta wheel = 1;
}

message ExecuteWheelDrawResponse {
  WheelDrawResult result = 1;
}

message GetWheelConfigRequest {
  RequestMeta meta = 1;
  string wheel_id = 2;
}

message GetWheelConfigResponse {
  WheelRuleConfig config = 1;
}

message UpsertWheelConfigRequest {
  RequestMeta meta = 1;
  WheelRuleConfig config = 2;
  int64 operator_admin_id = 3;
}

message UpsertWheelConfigResponse {
  WheelRuleConfig config = 1;
}

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

message ListWheelDrawsResponse {
  repeated WheelDrawResult draws = 1;
  int64 total = 2;
}

message WheelDrawSummary {
  string wheel_id = 1;
  int64 total_draws = 2;
  int64 unique_users = 3;
  int64 total_spent_coins = 4;
  int64 total_rtp_value_coins = 5;
  int64 actual_rtp_ppm = 6;
  int64 pending_draws = 7;
  int64 granted_draws = 8;
  int64 failed_draws = 9;
}

message GetWheelDrawSummaryRequest {
  RequestMeta meta = 1;
  string wheel_id = 2;
  int64 user_id = 3;
  string status = 4;
}

message GetWheelDrawSummaryResponse {
  WheelDrawSummary 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;
}

// CPWeeklyRankReward 是 CP 周榜名次对应的资源组奖励。
message CPWeeklyRankReward {
  int32 rank_no = 1;
  int64 resource_group_id = 2;
}

// CPWeeklyRankConfig 是 CP 周榜的全局启停和 Top 奖励配置。
message CPWeeklyRankConfig {
  string activity_code = 1;
  bool enabled = 2;
  string relation_type = 3;
  int32 top_count = 4;
  repeated CPWeeklyRankReward rewards = 5;
  int64 updated_by_admin_id = 6;
  int64 created_at_ms = 7;
  int64 updated_at_ms = 8;
  string app_code = 9;
}

// CPWeeklyRankUser 是 H5 周榜展示的一方用户快照。
message CPWeeklyRankUser {
  int64 user_id = 1;
  string display_user_id = 2;
  string username = 3;
  string avatar = 4;
}

// CPWeeklyRankEntry 是 activity-service 从 user-service 读取并返回 H5 的周榜条目。
message CPWeeklyRankEntry {
  int64 rank = 1;
  string relationship_id = 2;
  string relation_type = 3;
  int64 score = 4;
  CPWeeklyRankUser user_a = 5;
  CPWeeklyRankUser user_b = 6;
  int64 formed_at_ms = 7;
  int64 updated_at_ms = 8;
  int64 first_scored_at_ms = 9;
  int64 last_scored_at_ms = 10;
}

// CPWeeklyRankSettlement 是每周 cron 固化的一条用户发奖事实。
message CPWeeklyRankSettlement {
  string settlement_id = 1;
  int64 period_start_ms = 2;
  int64 period_end_ms = 3;
  int32 rank_no = 4;
  string relationship_id = 5;
  int64 user_id = 6;
  int64 score = 7;
  int64 resource_group_id = 8;
  string wallet_command_id = 9;
  string wallet_grant_id = 10;
  string status = 11;
  string failure_reason = 12;
  int32 attempt_count = 13;
  int64 created_at_ms = 14;
  int64 updated_at_ms = 15;
}

message GetCPWeeklyRankStatusRequest {
  RequestMeta meta = 1;
  int64 now_ms = 2;
  int32 limit = 3;
}

message GetCPWeeklyRankStatusResponse {
  CPWeeklyRankConfig config = 1;
  repeated CPWeeklyRankEntry entries = 2;
  int64 period_start_ms = 3;
  int64 period_end_ms = 4;
  int64 server_time_ms = 5;
  repeated CPWeeklyRankEntry previous_entries = 6;
}

message GetCPWeeklyRankConfigRequest {
  RequestMeta meta = 1;
}

message GetCPWeeklyRankConfigResponse {
  CPWeeklyRankConfig config = 1;
}

message UpdateCPWeeklyRankConfigRequest {
  RequestMeta meta = 1;
  CPWeeklyRankConfig config = 2;
  int64 operator_admin_id = 3;
}

message UpdateCPWeeklyRankConfigResponse {
  CPWeeklyRankConfig config = 1;
}

message ListCPWeeklyRankSettlementsRequest {
  RequestMeta meta = 1;
  int64 period_start_ms = 2;
  int64 period_end_ms = 3;
}

message ListCPWeeklyRankSettlementsResponse {
  repeated CPWeeklyRankSettlement settlements = 1;
}

// AgencyOpeningReward 是代理开业活动房间流水档位对应的金币奖励。
message AgencyOpeningReward {
  // rank_no 保留为档位展示顺序和旧字段兼容，结算不再按榜单名次发奖。
  int32 rank_no = 1;
  int64 reward_coin_amount = 2;
  int64 threshold_coin_spent = 3;
}

// AgencyOpeningCycle 是后台配置的代理开业活动周期。
message AgencyOpeningCycle {
  string cycle_id = 1;
  string activity_code = 2;
  string title = 3;
  string status = 4;
  int64 start_ms = 5;
  int64 end_ms = 6;
  int32 min_host_count = 7;
  int32 max_agency_age_days = 8;
  repeated AgencyOpeningReward 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;
  // region_id=0 表示全区域默认活动；正数表示只覆盖对应区域。
  int64 region_id = 16;
}

// AgencyOpeningApplication 是代理提交开业活动申请后的流水和发奖事实。
message AgencyOpeningApplication {
  string application_id = 1;
  string cycle_id = 2;
  int64 agency_id = 3;
  int64 agency_owner_user_id = 4;
  string agency_name = 5;
  int32 host_count = 6;
  int64 agency_created_at_ms = 7;
  string status = 8;
  int64 score_coin_amount = 9;
  int32 reward_rank_no = 10;
  int64 reward_coin_amount = 11;
  string wallet_command_id = 12;
  string wallet_transaction_id = 13;
  string failure_reason = 14;
  int64 applied_at_ms = 15;
  int64 granted_at_ms = 16;
  int64 updated_at_ms = 17;
  int64 reward_threshold_coin_spent = 18;
  int64 approved_at_ms = 19;
  int64 score_start_ms = 20;
  int64 score_end_ms = 21;
  int64 reviewed_by_admin_id = 22;
  // region_id 固化申请时代理所属区域，后续区域调整不改变已开始的计分事实。
  int64 region_id = 23;
}

// AgencyOpeningAgencySnapshot 是申请页展示和资格判断使用的代理快照。
message AgencyOpeningAgencySnapshot {
  int64 agency_id = 1;
  int64 owner_user_id = 2;
  string name = 3;
  string status = 4;
  int32 host_count = 5;
  int64 agency_created_at_ms = 6;
  int64 region_id = 7;
}

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

message ListAgencyOpeningCyclesResponse {
  repeated AgencyOpeningCycle cycles = 1;
  int64 total = 2;
}

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

message GetAgencyOpeningCycleResponse {
  AgencyOpeningCycle cycle = 1;
}

message UpsertAgencyOpeningCycleRequest {
  RequestMeta meta = 1;
  AgencyOpeningCycle cycle = 2;
  int64 operator_admin_id = 3;
}

message UpsertAgencyOpeningCycleResponse {
  AgencyOpeningCycle cycle = 1;
  bool created = 2;
}

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

message SetAgencyOpeningCycleStatusResponse {
  AgencyOpeningCycle cycle = 1;
}

message ListAgencyOpeningApplicationsRequest {
  RequestMeta meta = 1;
  string cycle_id = 2;
  string status = 3;
  int64 agency_id = 4;
  int64 agency_owner_user_id = 5;
  int32 page = 6;
  int32 page_size = 7;
  int64 region_id = 8;
}

message ListAgencyOpeningApplicationsResponse {
  repeated AgencyOpeningApplication applications = 1;
  int64 total = 2;
}

message ReviewAgencyOpeningApplicationRequest {
  RequestMeta meta = 1;
  string application_id = 2;
  string action = 3;
  int64 operator_admin_id = 4;
}

message ReviewAgencyOpeningApplicationResponse {
  AgencyOpeningApplication application = 1;
}

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

message GetAgencyOpeningStatusResponse {
  AgencyOpeningCycle cycle = 1;
  AgencyOpeningApplication application = 2;
  bool enabled = 3;
  bool eligible = 4;
  bool joined = 5;
  string ineligible_reason = 6;
  int64 server_time_ms = 7;
  AgencyOpeningAgencySnapshot agency = 8;
}

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

message ApplyAgencyOpeningResponse {
  AgencyOpeningApplication application = 1;
  bool created = 2;
}

// ActivityTemplateLocale 是活动模版的单语言文案。locale 使用 BCP-47 基础语言码，
// 当前运营后台至少配置 en，客户端按 locale -> en 的顺序回退。
message ActivityTemplateLocale {
  string locale = 1;
  string title = 2;
  string rules = 3;
}

// ActivityTemplateGift 是礼物挑战赛允许计分的礼物快照引用。
message ActivityTemplateGift {
  string gift_id = 1;
  int32 sort_order = 2;
  string name = 3;
  string icon_url = 4;
  int64 coin_price = 5;
  string price_version = 6;
}

// ActivityTemplateRewardItem 是 wallet pinned snapshot 的安全展示投影；不暴露发放策略和管理字段。
message ActivityTemplateRewardItem {
  string item_type = 1;
  int64 resource_id = 2;
  string resource_type = 3;
  string name = 4;
  string icon_url = 5;
  int64 quantity = 6;
  int64 duration_ms = 7;
  string wallet_asset_type = 8;
  int64 wallet_asset_amount = 9;
  int32 sort_order = 10;
}

// ActivityTemplateTask 表达模版内的一档每日任务。奖励使用 wallet-service 资源组，
// 由资源组负责展开头像框、座驾、金币等实际资产。
message ActivityTemplateTask {
  string task_key = 1;
  string task_type = 2;
  int64 target_value = 3;
  int64 reward_resource_group_id = 4;
  int32 sort_order = 5;
  string reward_snapshot_id = 6;
  string reward_snapshot_hash = 7;
  string reward_name = 8;
  repeated ActivityTemplateRewardItem reward_items = 9;
}

// ActivityTemplateRankReward 是日榜或总榜的一个不重叠名次区间奖励。
message ActivityTemplateRankReward {
  string board_type = 1;
  int32 rank_from = 2;
  int32 rank_to = 3;
  int64 resource_group_id = 4;
  int32 sort_order = 5;
  string reward_snapshot_id = 6;
  string reward_snapshot_hash = 7;
  string reward_name = 8;
  repeated ActivityTemplateRewardItem reward_items = 9;
}

// ActivityTemplateAsset 是客户端活动页素材引用。locale="*" 表示所有语言共享，
// 独立语言素材覆盖共享素材；media_type 支持 image/webp/svga/pag。
message ActivityTemplateAsset {
  string asset_key = 1;
  string locale = 2;
  string url = 3;
  string media_type = 4;
  int32 sort_order = 5;
}

// ActivityTemplate 是可排期的运营活动实例。运营侧沿用“活动模版”名称，
// 发布时 activity-service 会固化完整版本快照，避免运行中的配置被后台编辑覆盖。
message ActivityTemplate {
  string app_code = 1;
  string template_id = 2;
  string template_code = 3;
  string name = 4;
  string activity_type = 5;
  string status = 6;
  string lifecycle_status = 7;
  int64 start_ms = 8;
  int64 end_ms = 9;
  bool all_regions = 10;
  repeated int64 region_ids = 11;
  repeated ActivityTemplateLocale locales = 12;
  repeated ActivityTemplateGift gifts = 13;
  repeated ActivityTemplateTask tasks = 14;
  int32 daily_leaderboard_size = 15;
  int32 total_leaderboard_size = 16;
  repeated ActivityTemplateRankReward rank_rewards = 17;
  repeated ActivityTemplateAsset assets = 18;
  string display_config_json = 19;
  int64 revision = 20;
  int64 published_version = 21;
  int64 created_by_admin_id = 22;
  int64 updated_by_admin_id = 23;
  int64 published_by_admin_id = 24;
  int64 created_at_ms = 25;
  int64 updated_at_ms = 26;
  int64 published_at_ms = 27;
  int64 archived_at_ms = 28;
}

// ActivityTemplateSummary 是高密度列表专用投影，不携带规则、任务、素材和展示 JSON，
// 避免后台翻页时把每个模版的完整聚合重复传输。
message ActivityTemplateSummary {
  string app_code = 1;
  string template_id = 2;
  string template_code = 3;
  string name = 4;
  string activity_type = 5;
  string status = 6;
  string lifecycle_status = 7;
  int64 start_ms = 8;
  int64 end_ms = 9;
  bool all_regions = 10;
  repeated int64 region_ids = 11;
  int64 revision = 12;
  int64 published_version = 13;
  int64 created_by_admin_id = 14;
  int64 updated_by_admin_id = 15;
  int64 created_at_ms = 16;
  int64 updated_at_ms = 17;
}

message ListActivityTemplatesRequest {
  RequestMeta meta = 1;
  string keyword = 2;
  string status = 3;
  optional int64 region_id = 4;
  int64 start_ms = 5;
  int64 end_ms = 6;
  int32 page = 7;
  int32 page_size = 8;
  optional bool all_regions = 9;
}

message ListActivityTemplatesResponse {
  repeated ActivityTemplateSummary templates = 1;
  int64 total = 2;
  int64 server_time_ms = 3;
}

message CreateActivityTemplateRequest {
  RequestMeta meta = 1;
  ActivityTemplate template = 2;
  int64 operator_admin_id = 3;
}

message CreateActivityTemplateResponse {
  ActivityTemplate template = 1;
}

message GetActivityTemplateRequest {
  RequestMeta meta = 1;
  string template_id = 2;
}

message GetActivityTemplateResponse {
  ActivityTemplate template = 1;
}

message UpdateActivityTemplateRequest {
  RequestMeta meta = 1;
  ActivityTemplate template = 2;
  int64 expected_revision = 3;
  int64 operator_admin_id = 4;
}

message UpdateActivityTemplateResponse {
  ActivityTemplate template = 1;
}

message SetActivityTemplateStatusRequest {
  RequestMeta meta = 1;
  string template_id = 2;
  string status = 3;
  int64 expected_revision = 4;
  int64 operator_admin_id = 5;
}

message SetActivityTemplateStatusResponse {
  ActivityTemplate template = 1;
}

message DeleteActivityTemplateRequest {
  RequestMeta meta = 1;
  string template_id = 2;
  int64 expected_revision = 3;
  int64 operator_admin_id = 4;
}

message DeleteActivityTemplateResponse {
  ActivityTemplate template = 1;
  bool archived = 2;
}

// ActivityTemplateVersion 是每次发布形成的不可变完整配置快照。
message ActivityTemplateVersion {
  string template_id = 1;
  int64 version_no = 2;
  ActivityTemplate snapshot = 3;
  int64 published_by_admin_id = 4;
  int64 published_at_ms = 5;
  // 实际运行窗口来自 activity_template_runtime_versions；停用后 runtime_to_ms 固化，重发会创建新版本窗口。
  int64 runtime_from_ms = 6;
  int64 runtime_to_ms = 7;
}

message ListActivityTemplateVersionsRequest {
  RequestMeta meta = 1;
  string template_id = 2;
  int32 page = 3;
  int32 page_size = 4;
}

message ListActivityTemplateVersionsResponse {
  repeated ActivityTemplateVersion versions = 1;
  int64 total = 2;
}

// CloneActivityTemplateRequest 从当前配置或指定发布版本复制为新草稿；
// source_version=0 表示复制当前配置，新的 template_code 必须在 App 内唯一。
message CloneActivityTemplateRequest {
  RequestMeta meta = 1;
  string source_template_id = 2;
  int64 source_version = 3;
  string template_code = 4;
  string name = 5;
  int64 operator_admin_id = 6;
}

message CloneActivityTemplateResponse {
  ActivityTemplate template = 1;
}

message ActivityTemplateValidationIssue {
  string field = 1;
  string code = 2;
  string message = 3;
}

// ValidateActivityTemplateRequest 让编辑页在正式保存或发布前复用 owner service 的校验规则。
message ValidateActivityTemplateRequest {
  RequestMeta meta = 1;
  ActivityTemplate template = 2;
  bool for_publish = 3;
}

message ValidateActivityTemplateResponse {
  bool valid = 1;
  repeated ActivityTemplateValidationIssue issues = 2;
}

// ActivityTemplateRuntime 描述一个用户当前命中的已发布不可变版本。
// runtime_from_ms/runtime_to_ms 是该版本的实际启停窗口，活动排期仍以 template 的 [start_ms,end_ms) 为准。
message ActivityTemplateRuntime {
  ActivityTemplate template = 1;
  int64 version_no = 2;
  int64 runtime_from_ms = 3;
  int64 runtime_to_ms = 4;
  int64 server_time_ms = 5;
}

// ActivityTemplateRuntimeTask 是发布版本内一档 UTC 每日任务及当前用户进度。
message ActivityTemplateRuntimeTask {
  string template_id = 1;
  string template_code = 2;
  int64 version_no = 3;
  string task_day = 4;
  string task_key = 5;
  string task_type = 6;
  int64 target_value = 7;
  int64 progress_value = 8;
  int64 reward_resource_group_id = 9;
  string status = 10;
  bool claimable = 11;
  int64 completed_at_ms = 12;
  int64 claimed_at_ms = 13;
  int32 sort_order = 14;
  string reward_snapshot_id = 15;
  string reward_snapshot_hash = 16;
  string reward_name = 17;
  repeated ActivityTemplateRewardItem reward_items = 18;
}

// ActivityTemplateTaskClaim 是 activity-service 与 wallet-service 之间可审计、可重放的领奖事实。
message ActivityTemplateTaskClaim {
  string claim_id = 1;
  string command_id = 2;
  string template_id = 3;
  string template_code = 4;
  int64 version_no = 5;
  string task_day = 6;
  string task_key = 7;
  int64 user_id = 8;
  int64 reward_resource_group_id = 9;
  string wallet_command_id = 10;
  string wallet_grant_id = 11;
  string status = 12;
  string failure_reason = 13;
  int32 attempt_count = 14;
  int64 created_at_ms = 15;
  int64 updated_at_ms = 16;
  int64 granted_at_ms = 17;
  string reward_snapshot_id = 18;
  string reward_name = 19;
  repeated ActivityTemplateRewardItem reward_items = 20;
  string reward_snapshot_hash = 21;
  // earning_region_id/attribution_at_ms are frozen from the progress event that completed the task.
  int64 earning_region_id = 22;
  int64 attribution_at_ms = 23;
}

// ActivityTemplateLeaderboardEntry 同时用于实时榜和结算后冻结快照。
message ActivityTemplateLeaderboardEntry {
  int32 rank_no = 1;
  int64 user_id = 2;
  int64 score = 3;
  int64 gift_count = 4;
  int64 coin_amount = 5;
  int64 first_scored_at_ms = 6;
  bool snapshot = 7;
}

message GetCurrentActivityTemplateRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  int64 region_id = 3;
  string locale = 4;
  // template_code 为空时保留历史“当前活动”解析；Banner/H5 必须显式传值，
  // 避免未来同一 App 存在多种活动页时点击入口却命中另一份运行态。
  string template_code = 5;
}

message GetCurrentActivityTemplateResponse {
  ActivityTemplateRuntime runtime = 1;
  bool found = 2;
}

// VisitActivityTemplate 是 daily_visit 的唯一事实入口；command_id 负责请求重放，
// 自然幂等键仍是用户+发布版本+UTC task_day。
message VisitActivityTemplateRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  int64 region_id = 3;
  string template_code = 4;
  string command_id = 5;
  // version_no comes from GetCurrentActivityTemplate and prevents disable/re-publish races.
  int64 version_no = 6;
}

message VisitActivityTemplateResponse {
  ActivityTemplateRuntime runtime = 1;
  repeated ActivityTemplateRuntimeTask tasks = 2;
  bool first_visit = 3;
}

message ListActivityTemplateTasksRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  int64 region_id = 3;
  string template_code = 4;
  string task_day = 5;
  // version_no 与 task_day 同时提供时读取该用户确实参与过的历史不可变任务版本。
  int64 version_no = 6;
}

message ListActivityTemplateTasksResponse {
  ActivityTemplateRuntime runtime = 1;
  repeated ActivityTemplateRuntimeTask tasks = 2;
  int64 next_refresh_at_ms = 3;
}

message ClaimActivityTemplateTaskRewardRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  int64 region_id = 3;
  string template_code = 4;
  string task_day = 5;
  string task_key = 6;
  string command_id = 7;
  // version_no 来自 tasks/runtime 响应，强制把同日重发前后的任务领奖绑定到正确不可变版本。
  int64 version_no = 8;
}

message ClaimActivityTemplateTaskRewardResponse {
  ActivityTemplateTaskClaim claim = 1;
  bool claimed = 2;
}

message ListActivityTemplateLeaderboardRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  int64 region_id = 3;
  string template_code = 4;
  string board_type = 5;
  string period_key = 6;
  int32 page = 7;
  int32 page_size = 8;
  // version_no > 0 时严格读取该发布版本；省略仅用于当前/最近版本兼容查询。
  int64 version_no = 9;
}

message ListActivityTemplateLeaderboardResponse {
  ActivityTemplateRuntime runtime = 1;
  string board_type = 2;
  string period_key = 3;
  int64 period_start_ms = 4;
  int64 period_end_ms = 5;
  string period_status = 6;
  repeated ActivityTemplateLeaderboardEntry entries = 7;
  ActivityTemplateLeaderboardEntry my_entry = 8;
  int64 total = 9;
  // settle_after_ms 是含迟到窗口的排他结算水位；到达该毫秒后榜单不再接收事件。
  int64 settle_after_ms = 10;
}

// ActivityTemplateRankPeriod 是 UTC 日榜或活动总榜的冻结/发奖状态机。
message ActivityTemplateRankPeriod {
  string template_id = 1;
  string template_code = 2;
  int64 version_no = 3;
  string board_type = 4;
  string period_key = 5;
  int64 period_start_ms = 6;
  int64 period_end_ms = 7;
  // pending -> settling（物化中）-> rewarding（奖励 job 独立推进）-> settled；也可 cancelled。
  string status = 8;
  int64 settled_at_ms = 9;
  int64 settle_after_ms = 10;
}

message ActivityTemplateRewardJob {
  string reward_job_id = 1;
  string template_id = 2;
  string template_code = 3;
  int64 version_no = 4;
  string board_type = 5;
  string period_key = 6;
  int32 rank_no = 7;
  int64 user_id = 8;
  int64 score = 9;
  int64 resource_group_id = 10;
  string wallet_command_id = 11;
  string wallet_grant_id = 12;
  string status = 13;
  string failure_reason = 14;
  int32 attempt_count = 15;
  int64 created_at_ms = 16;
  int64 updated_at_ms = 17;
  int64 granted_at_ms = 18;
  string reward_snapshot_id = 19;
  string reward_snapshot_hash = 20;
  string reward_name = 21;
  repeated ActivityTemplateRewardItem reward_items = 22;
  int32 max_attempts = 23;
  int64 next_retry_at_ms = 24;
}

message AdminListActivityTemplateLeaderboardRequest {
  RequestMeta meta = 1;
  string template_id = 2;
  int64 version_no = 3;
  string board_type = 4;
  string period_key = 5;
  int32 page = 6;
  int32 page_size = 7;
}

message AdminListActivityTemplateLeaderboardResponse {
  ActivityTemplateRankPeriod period = 1;
  repeated ActivityTemplateLeaderboardEntry entries = 2;
  int64 total = 3;
}

message ListActivityTemplateRewardJobsRequest {
  RequestMeta meta = 1;
  string template_id = 2;
  int64 version_no = 3;
  string board_type = 4;
  string period_key = 5;
  string status = 6;
  int32 page = 7;
  int32 page_size = 8;
}

message ListActivityTemplateRewardJobsResponse {
  repeated ActivityTemplateRewardJob jobs = 1;
  int64 total = 2;
}

message RetryActivityTemplateRewardJobRequest {
  RequestMeta meta = 1;
  string template_id = 2;
  string reward_job_id = 3;
  int64 operator_admin_id = 4;
}

message RetryActivityTemplateRewardJobResponse {
  ActivityTemplateRewardJob job = 1;
}

message ListActivityTemplateTaskClaimsRequest {
  RequestMeta meta = 1;
  string template_id = 2;
  int64 version_no = 3;
  string task_day = 4;
  string task_key = 5;
  int64 user_id = 6;
  string status = 7;
  int32 page = 8;
  int32 page_size = 9;
}

message ListActivityTemplateTaskClaimsResponse {
  repeated ActivityTemplateTaskClaim claims = 1;
  int64 total = 2;
}

message RetryActivityTemplateTaskClaimRequest {
  RequestMeta meta = 1;
  string template_id = 2;
  string claim_id = 3;
  int64 operator_admin_id = 4;
}

message RetryActivityTemplateTaskClaimResponse {
  ActivityTemplateTaskClaim claim = 1;
}

// InboxRewardItem 放在既有 message 声明之后，避免新增结构导致生成代码中历史消息索引整体漂移。
message InboxRewardItem {
  // reward_type 仅使用 resource/coin；客户端据此选择远程素材预览图或当前 App 金币图。
  string reward_type = 1;
  string name = 2;
  string image_url = 3;
  int64 quantity = 4;
  int64 duration_days = 5;
}

// InboxActionAPI 是后端下发的同源 App API 请求；Flutter 只执行相对 /api/v1 路径，
// 不接收 headers、host 或自定义 scheme，避免通知内容绕过统一鉴权和租户请求头。
message InboxActionAPI {
  string method = 1;
  string path = 2;
  string query_json = 3;
  string body_json = 4;
}

// InboxAction 与 C2C im_confirm.actions 保持相同的按钮展示语义；label 完全由后端提供。
message InboxAction {
  string action = 1;
  string label = 2;
  string style = 3;
  InboxActionAPI api = 4;
}

// 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);
}

// MessageActionConfirmService 拥有 IM 操作按钮的确认状态，业务执行仍回到 owner service。
service MessageActionConfirmService {
  rpc AcceptActionConfirm(AcceptActionConfirmRequest) returns (AcceptActionConfirmResponse);
  rpc RejectActionConfirm(RejectActionConfirmRequest) returns (RejectActionConfirmResponse);
  rpc BatchGetActionConfirmStatus(BatchGetActionConfirmStatusRequest) returns (BatchGetActionConfirmStatusResponse);
  rpc ListConversationActionConfirms(ListConversationActionConfirmsRequest) returns (ListConversationActionConfirmsResponse);
}

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

// ActivityTemplateRuntimeService 是 App/H5 读取已发布版本、任务进度、榜单和领奖的 owner 入口。
service ActivityTemplateRuntimeService {
  rpc GetCurrentActivityTemplate(GetCurrentActivityTemplateRequest) returns (GetCurrentActivityTemplateResponse);
  rpc VisitActivityTemplate(VisitActivityTemplateRequest) returns (VisitActivityTemplateResponse);
  rpc ListActivityTemplateTasks(ListActivityTemplateTasksRequest) returns (ListActivityTemplateTasksResponse);
  rpc ClaimActivityTemplateTaskReward(ClaimActivityTemplateTaskRewardRequest) returns (ClaimActivityTemplateTaskRewardResponse);
  rpc ListActivityTemplateLeaderboard(ListActivityTemplateLeaderboardRequest) returns (ListActivityTemplateLeaderboardResponse);
}

// 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);
}

// WheelService owns wheel draw decisions after wallet debit succeeds.
service WheelService {
  rpc ExecuteWheelDraw(ExecuteWheelDrawRequest) returns (ExecuteWheelDrawResponse);
}

// 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);
}

// CPWeeklyRankService owns H5 reads for CP weekly rank and reward config.
service CPWeeklyRankService {
  rpc GetCPWeeklyRankStatus(GetCPWeeklyRankStatusRequest) returns (GetCPWeeklyRankStatusResponse);
}

// AgencyOpeningService owns App/H5 reads and application writes for agency opening activity.
service AgencyOpeningService {
  rpc GetAgencyOpeningStatus(GetAgencyOpeningStatusRequest) returns (GetAgencyOpeningStatusResponse);
  rpc ApplyAgencyOpening(ApplyAgencyOpeningRequest) returns (ApplyAgencyOpeningResponse);
  rpc ListAgencyOpeningLeaderboard(ListAgencyOpeningApplicationsRequest) returns (ListAgencyOpeningApplicationsResponse);
}

// 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);
}

// AdminBroadcastService 是后台读写飘屏策略的唯一入口；配置仍由 activity-service 持久化和执行。
service AdminBroadcastService {
  rpc GetGameWinBroadcastConfig(GetGameWinBroadcastConfigRequest) returns (GetGameWinBroadcastConfigResponse);
  rpc UpdateGameWinBroadcastConfig(UpdateGameWinBroadcastConfigRequest) returns (UpdateGameWinBroadcastConfigResponse);
}

// 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);
  rpc PublishTaskRewardPolicy(PublishTaskRewardPolicyRequest) returns (PublishTaskRewardPolicyResponse) {
    option deprecated = true;
  }
}

// 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);
}

// InviteActivityRewardService 拥有 App 邀请活动状态、领奖和排行榜入口。
service InviteActivityRewardService {
  rpc GetInviteActivityRewardStatus(GetInviteActivityRewardStatusRequest) returns (GetInviteActivityRewardStatusResponse);
  rpc ClaimInviteActivityReward(ClaimInviteActivityRewardRequest) returns (ClaimInviteActivityRewardResponse);
  rpc ListInviteActivityLeaderboard(ListInviteActivityLeaderboardRequest) returns (ListInviteActivityLeaderboardResponse);
  rpc ListInviteActivityInvitees(ListInviteActivityInviteesRequest) returns (ListInviteActivityInviteesResponse);
}

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

// AdminInviteActivityRewardService 是后台活动管理访问邀请活动配置和领取记录的唯一入口。
service AdminInviteActivityRewardService {
  rpc GetInviteActivityRewardConfig(GetInviteActivityRewardConfigRequest) returns (GetInviteActivityRewardConfigResponse);
  rpc UpdateInviteActivityRewardConfig(UpdateInviteActivityRewardConfigRequest) returns (UpdateInviteActivityRewardConfigResponse);
  rpc ListInviteActivityRewardClaims(ListInviteActivityRewardClaimsRequest) returns (ListInviteActivityRewardClaimsResponse);
  rpc ListInviteActivityRewardSummaries(ListInviteActivityRewardSummariesRequest) returns (ListInviteActivityRewardSummariesResponse);
}

// 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);
}

// AdminCPWeeklyRankService 是后台配置 CP 周榜启停、奖励和查询发奖事实的入口。
service AdminCPWeeklyRankService {
  rpc GetCPWeeklyRankConfig(GetCPWeeklyRankConfigRequest) returns (GetCPWeeklyRankConfigResponse);
  rpc UpdateCPWeeklyRankConfig(UpdateCPWeeklyRankConfigRequest) returns (UpdateCPWeeklyRankConfigResponse);
  rpc ListCPWeeklyRankSettlements(ListCPWeeklyRankSettlementsRequest) returns (ListCPWeeklyRankSettlementsResponse);
}

// AdminAgencyOpeningService 是后台配置开业周期、查看申请和榜单发奖结果的入口。
service AdminAgencyOpeningService {
  rpc ListAgencyOpeningCycles(ListAgencyOpeningCyclesRequest) returns (ListAgencyOpeningCyclesResponse);
  rpc CreateAgencyOpeningCycle(UpsertAgencyOpeningCycleRequest) returns (UpsertAgencyOpeningCycleResponse);
  rpc GetAgencyOpeningCycle(GetAgencyOpeningCycleRequest) returns (GetAgencyOpeningCycleResponse);
  rpc UpdateAgencyOpeningCycle(UpsertAgencyOpeningCycleRequest) returns (UpsertAgencyOpeningCycleResponse);
  rpc SetAgencyOpeningCycleStatus(SetAgencyOpeningCycleStatusRequest) returns (SetAgencyOpeningCycleStatusResponse);
  rpc ListAgencyOpeningApplications(ListAgencyOpeningApplicationsRequest) returns (ListAgencyOpeningApplicationsResponse);
  rpc ReviewAgencyOpeningApplication(ReviewAgencyOpeningApplicationRequest) returns (ReviewAgencyOpeningApplicationResponse);
}

// AdminActivityTemplateService 是后台活动模版访问 activity-service 的唯一入口。
// admin-server 只做鉴权、协议转换和审计，不能直写 activity-service 的配置表。
service AdminActivityTemplateService {
  rpc ListActivityTemplates(ListActivityTemplatesRequest) returns (ListActivityTemplatesResponse);
  rpc CreateActivityTemplate(CreateActivityTemplateRequest) returns (CreateActivityTemplateResponse);
  rpc GetActivityTemplate(GetActivityTemplateRequest) returns (GetActivityTemplateResponse);
  rpc UpdateActivityTemplate(UpdateActivityTemplateRequest) returns (UpdateActivityTemplateResponse);
  rpc SetActivityTemplateStatus(SetActivityTemplateStatusRequest) returns (SetActivityTemplateStatusResponse);
  rpc DeleteActivityTemplate(DeleteActivityTemplateRequest) returns (DeleteActivityTemplateResponse);
  rpc ListActivityTemplateVersions(ListActivityTemplateVersionsRequest) returns (ListActivityTemplateVersionsResponse);
  rpc CloneActivityTemplate(CloneActivityTemplateRequest) returns (CloneActivityTemplateResponse);
  rpc ValidateActivityTemplate(ValidateActivityTemplateRequest) returns (ValidateActivityTemplateResponse);
  rpc ListActivityTemplateLeaderboard(AdminListActivityTemplateLeaderboardRequest) returns (AdminListActivityTemplateLeaderboardResponse);
  rpc ListActivityTemplateRewardJobs(ListActivityTemplateRewardJobsRequest) returns (ListActivityTemplateRewardJobsResponse);
  rpc RetryActivityTemplateRewardJob(RetryActivityTemplateRewardJobRequest) returns (RetryActivityTemplateRewardJobResponse);
  rpc ListActivityTemplateTaskClaims(ListActivityTemplateTaskClaimsRequest) returns (ListActivityTemplateTaskClaimsResponse);
  rpc RetryActivityTemplateTaskClaim(RetryActivityTemplateTaskClaimRequest) returns (RetryActivityTemplateTaskClaimResponse);
}

// 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);
  rpc BatchUpsertLevelConfig(BatchUpsertLevelConfigRequest) returns (BatchUpsertLevelConfigResponse);
  rpc BatchGetUserLevelAdminProfiles(BatchGetUserLevelAdminProfilesRequest) returns (BatchGetUserLevelAdminProfilesResponse);
  rpc AdjustTemporaryUserLevels(AdjustTemporaryUserLevelsRequest) returns (AdjustTemporaryUserLevelsResponse);
}

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

// AdminWheelService is the admin entry for wheel rule versions, draw records, and RTP statistics.
service AdminWheelService {
  rpc GetWheelConfig(GetWheelConfigRequest) returns (GetWheelConfigResponse);
  rpc UpsertWheelConfig(UpsertWheelConfigRequest) returns (UpsertWheelConfigResponse);
  rpc ListWheelDraws(ListWheelDrawsRequest) returns (ListWheelDrawsResponse);
  rpc GetWheelDrawSummary(GetWheelDrawSummaryRequest) returns (GetWheelDrawSummaryResponse);
}
