syntax = "proto3";

package hyapp.wallet.v1;

option go_package = "hyapp.local/api/proto/wallet/v1;walletv1";

// DebitGiftRequest 是 room-service 送礼同步扣费的最小账务输入。
message DebitGiftRequest {
  string command_id = 1;
  string room_id = 2;
  int64 sender_user_id = 3;
  int64 target_user_id = 4;
  string gift_id = 5;
  int32 gift_count = 6;
  // price_version 为空时使用当前生效价格；非空时必须命中 active 价格版本。
  string price_version = 7;
  string app_code = 8;
  // region_id 来自 room-service 房间 visible_region_id，用于校验礼物区域可用性和匹配房间贡献比例。
  int64 region_id = 9;
  // target_is_host 由 gateway 根据 user-service active host profile 注入，客户端不能直接声明。
  bool target_is_host = 10;
  // target_host_region_id 是主播身份所属区域，用于后续按主播区域匹配工资政策。
  int64 target_host_region_id = 11;
  // target_agency_owner_user_id 是送礼时主播归属 Agency 的 owner，用于后续代理工资结算。
  int64 target_agency_owner_user_id = 12;
  // sender_region_id 是送礼用户所属区域快照；不能用房间 visible_region_id 替代。
  int64 sender_region_id = 13;
  // entitlement_id 非空表示本次送礼从用户背包 gift 权益扣库存，不扣 COIN。
  string entitlement_id = 14;
  // charge_source 区分 coin/bag；为空按 coin 兼容旧客户端。
  string charge_source = 15;
}

// DebitDirectGiftRequest 是私聊送礼的账务命令；gateway 负责用 user-service 补齐区域和主播身份。
message DebitDirectGiftRequest {
  string command_id = 1;
  int64 sender_user_id = 2;
  int64 target_user_id = 3;
  string gift_id = 4;
  int32 gift_count = 5;
  string price_version = 6;
  string app_code = 7;
  // region_id 使用 sender 当前 region_id；私聊没有房间可见区域，不能接收客户端自报区域。
  int64 region_id = 8;
  int64 sender_region_id = 9;
  bool target_is_host = 10;
  int64 target_host_region_id = 11;
  int64 target_agency_owner_user_id = 12;
  string entitlement_id = 13;
  string charge_source = 14;
}

// DebitGiftResponse 返回扣费流水、服务端结算值和 sender COIN 账后余额。
message DebitGiftResponse {
  string billing_receipt_id = 1;
  string transaction_id = 2;
  int64 coin_spent = 3;
  // gift_point_added 是历史回执字段；GIFT_POINT 已下线，新送礼固定返回 0。
  int64 gift_point_added = 4;
  int64 heat_value = 5;
  string price_version = 6;
  // balance_after 是 sender 被扣费资产 available_amount 账后余额。
  int64 balance_after = 7;
  string charge_asset_type = 8;
  int64 charge_amount = 9;
  string gift_type_code = 10;
  // host_period_diamond_added 是本次送礼给主播周期钻石账户增加的钻石；非主播为 0。
  int64 host_period_diamond_added = 11;
  // host_period_cycle_key 是 UTC 月周期，例如 2026-05；非主播为空。
  string host_period_cycle_key = 12;
  // cp_relation_type 只在 CP 礼物、兄弟礼物、姐妹礼物上有值，用于 room outbox 驱动关系申请。
  string cp_relation_type = 13;
  string gift_name = 14;
  string gift_icon_url = 15;
  string gift_animation_url = 16;
  repeated string gift_effect_types = 17;
  string entitlement_id = 18;
  string charge_source = 19;
  // gift_income_coin_amount 是本次给收礼人返还的 COIN；0 表示当前礼物类型/区域不返币。
  int64 gift_income_coin_amount = 20;
  // gift_income_balance_after 是收礼人 COIN 账后余额；未返币时为 0。
  int64 gift_income_balance_after = 21;
}

// DebitGiftTarget 是一笔批量送礼中的单个接收方账务快照。
message DebitGiftTarget {
  // command_id 是该目标的账务幂等键，由 room-service 从房间 command_id 派生。
  string command_id = 1;
  int64 target_user_id = 2;
  bool target_is_host = 3;
  int64 target_host_region_id = 4;
  int64 target_agency_owner_user_id = 5;
}

// BatchDebitGiftRequest 在一个钱包事务内完成同一 sender 对多个 target 的送礼扣费。
message BatchDebitGiftRequest {
  string command_id = 1;
  string room_id = 2;
  int64 sender_user_id = 3;
  string gift_id = 4;
  int32 gift_count = 5;
  string price_version = 6;
  string app_code = 7;
  // region_id 来自 room-service 房间 visible_region_id，用于校验礼物区域可用性和匹配房间贡献比例。
  int64 region_id = 8;
  int64 sender_region_id = 9;
  repeated DebitGiftTarget targets = 10;
  string entitlement_id = 11;
  string charge_source = 12;
}

// BatchDebitGiftReceipt 保留每个目标独立交易的回执，房间事件按它逐目标落事实。
message BatchDebitGiftReceipt {
  int64 target_user_id = 1;
  string command_id = 2;
  DebitGiftResponse billing = 3;
}

// BatchDebitGiftResponse 返回批量聚合值和逐目标账务回执。
message BatchDebitGiftResponse {
  DebitGiftResponse aggregate = 1;
  repeated BatchDebitGiftReceipt receipts = 2;
}

// DebitRobotGiftRequest 是机器人房间内部送礼扣费命令。
// 它只扣 ROBOT_COIN，不产生主播钻石、真实充值消费流水或普通礼物墙投影。
message DebitRobotGiftRequest {
  string command_id = 1;
  string room_id = 2;
  int64 sender_user_id = 3;
  int64 target_user_id = 4;
  string gift_id = 5;
  int32 gift_count = 6;
  string price_version = 7;
  string app_code = 8;
  int64 region_id = 9;
  int64 sender_region_id = 10;
}

// AssetBalance 是用户某类资产的余额投影。
message AssetBalance {
  string asset_type = 1;
  int64 available_amount = 2;
  int64 frozen_amount = 3;
  int64 version = 4;
  string app_code = 5;
}

// GetBalancesRequest 查询用户多资产余额；内部调用方负责鉴权和用户范围控制。
message GetBalancesRequest {
  string request_id = 1;
  int64 user_id = 2;
  repeated string asset_types = 3;
  string app_code = 4;
}

message GetBalancesResponse {
  repeated AssetBalance balances = 1;
}

message HostSalaryPolicyLevel {
  int32 level_no = 1;
  int64 required_diamonds = 2;
  int64 host_salary_usd_minor = 3;
  int64 host_coin_reward = 4;
  int64 agency_salary_usd_minor = 5;
  string status = 6;
  int32 sort_order = 7;
}

message HostSalaryPolicy {
  uint64 policy_id = 1;
  string name = 2;
  int64 region_id = 3;
  string status = 4;
  string settlement_mode = 5;
  string settlement_trigger_mode = 6;
  string gift_coin_to_diamond_ratio = 7;
  string residual_diamond_to_usd_rate = 8;
  int64 effective_from_ms = 9;
  int64 effective_to_ms = 10;
  repeated HostSalaryPolicyLevel levels = 11;
}

message GetActiveHostSalaryPolicyRequest {
  string request_id = 1;
  string app_code = 2;
  int64 region_id = 3;
  string settlement_mode = 4;
  string settlement_trigger_mode = 5;
  int64 now_ms = 6;
}

message GetActiveHostSalaryPolicyResponse {
  bool found = 1;
  HostSalaryPolicy policy = 2;
}

message HostSalaryProgress {
  int64 host_user_id = 1;
  string cycle_key = 2;
  int64 region_id = 3;
  int64 agency_owner_user_id = 4;
  int64 total_diamonds = 5;
  int64 gift_diamond_total = 6;
  int64 updated_at_ms = 7;
}

message GetHostSalaryProgressRequest {
  string request_id = 1;
  string app_code = 2;
  int64 host_user_id = 3;
  string cycle_key = 4;
  int64 now_ms = 5;
}

message GetHostSalaryProgressResponse {
  HostSalaryProgress progress = 1;
}

// AdminCreditAssetRequest 是后台手动入账/调账的最小审计命令。
message AdminCreditAssetRequest {
  string command_id = 1;
  int64 target_user_id = 2;
  string asset_type = 3;
  int64 amount = 4;
  int64 operator_user_id = 5;
  string reason = 6;
  string evidence_ref = 7;
  string app_code = 8;
}

message AdminCreditAssetResponse {
  string transaction_id = 1;
  AssetBalance balance = 2;
}

// AdminCreditCoinSellerStockRequest 是后台调整币商专用库存的账务命令。
message AdminCreditCoinSellerStockRequest {
  string command_id = 1;
  int64 seller_user_id = 2;
  string stock_type = 3;
  int64 coin_amount = 4;
  string paid_currency_code = 5;
  int64 paid_amount_micro = 6;
  string payment_ref = 7;
  string evidence_ref = 8;
  int64 operator_user_id = 9;
  string reason = 10;
  string app_code = 11;
  int64 seller_country_id = 12;
  int64 seller_region_id = 13;
}

message AdminCreditCoinSellerStockResponse {
  string transaction_id = 1;
  int64 seller_user_id = 2;
  string stock_type = 3;
  int64 coin_amount = 4;
  string paid_currency_code = 5;
  int64 paid_amount_micro = 6;
  bool counts_as_seller_recharge = 7;
  int64 balance_after = 8;
  int64 created_at_ms = 9;
}

// TransferCoinFromSellerRequest 是币商给玩家转普通金币的内部账务命令。
message TransferCoinFromSellerRequest {
  string command_id = 1;
  int64 seller_user_id = 2;
  int64 target_user_id = 3;
  int64 amount = 4;
  string reason = 5;
  string app_code = 6;
  // seller_region_id、target_region_id 和 target_country_id 由 gateway 从 user-service 查询，不接受客户端提交。
  int64 seller_region_id = 7;
  int64 target_region_id = 8;
  int64 target_country_id = 9;
}

// TransferCoinFromSellerResponse 同时返回金币到账结果和本次转账对应的充值金额口径。
message TransferCoinFromSellerResponse {
  string transaction_id = 1;
  int64 seller_balance_after = 2;
  int64 target_balance_after = 3;
  int64 amount = 4;
  int64 recharge_usd_minor = 5;
  string recharge_currency_code = 6;
  int64 recharge_policy_id = 7;
  string recharge_policy_version = 8;
  int64 recharge_policy_coin_amount = 9;
  int64 recharge_policy_usd_minor_amount = 10;
}

// CoinSellerSalaryExchangeRateTier 是用户工资转给币商时，按区域和美元金额命中的金币兑换区间。
message CoinSellerSalaryExchangeRateTier {
  int64 region_id = 1;
  int64 min_usd_minor = 2;
  int64 max_usd_minor = 3;
  int64 coin_per_usd = 4;
  string status = 5;
  int32 sort_order = 6;
  int64 updated_at_ms = 7;
}

message ListCoinSellerSalaryExchangeRateTiersRequest {
  string request_id = 1;
  string app_code = 2;
  int64 region_id = 3;
  bool include_disabled = 4;
}

message ListCoinSellerSalaryExchangeRateTiersResponse {
  repeated CoinSellerSalaryExchangeRateTier tiers = 1;
}

// ExchangeSalaryToCoinRequest 扣当前用户某个身份工资美元钱包，并按固定比例给同一用户加普通 COIN。
message ExchangeSalaryToCoinRequest {
  string command_id = 1;
  int64 user_id = 2;
  string salary_asset_type = 3;
  int64 salary_usd_minor = 4;
  string reason = 5;
  string app_code = 6;
}

message ExchangeSalaryToCoinResponse {
  string transaction_id = 1;
  int64 salary_balance_after = 2;
  int64 coin_balance_after = 3;
  int64 salary_usd_minor = 4;
  int64 coin_amount = 5;
  int64 coin_per_usd = 6;
}

// TransferSalaryToCoinSellerRequest 扣当前用户某个身份工资美元钱包，并按区域区间比例给同区域币商加专用金币库存。
message TransferSalaryToCoinSellerRequest {
  string command_id = 1;
  int64 source_user_id = 2;
  int64 seller_user_id = 3;
  string salary_asset_type = 4;
  int64 salary_usd_minor = 5;
  int64 region_id = 6;
  string reason = 7;
  string app_code = 8;
}

message TransferSalaryToCoinSellerResponse {
  string transaction_id = 1;
  int64 source_salary_balance_after = 2;
  int64 seller_balance_after = 3;
  int64 salary_usd_minor = 4;
  int64 coin_amount = 5;
  int64 coin_per_usd = 6;
  int64 rate_min_usd_minor = 7;
  int64 rate_max_usd_minor = 8;
}

// Resource 是资源库里可配置、可赠送、可被礼物引用的最小资源。
message Resource {
  string app_code = 1;
  int64 resource_id = 2;
  string resource_code = 3;
  string resource_type = 4;
  string name = 5;
  string status = 6;
  bool grantable = 7;
  string grant_strategy = 8;
  string wallet_asset_type = 9;
  int64 wallet_asset_amount = 10;
  repeated string usage_scopes = 11;
  string asset_url = 12;
  string preview_url = 13;
  string animation_url = 14;
  string metadata_json = 15;
  int32 sort_order = 16;
  int64 created_by_user_id = 17;
  int64 updated_by_user_id = 18;
  int64 created_at_ms = 19;
  int64 updated_at_ms = 20;
  bool manager_grant_enabled = 21;
  string price_type = 22;
  int64 coin_price = 23;
  // gift_point_amount 是历史字段；资源和礼物价格现在只维护真实 COIN 价格，新写入固定为 0。
  int64 gift_point_amount = 24;
}

message ResourceGroupItem {
  int64 group_item_id = 1;
  int64 group_id = 2;
  int64 resource_id = 3;
  Resource resource = 4;
  int64 quantity = 5;
  int64 duration_ms = 6;
  int32 sort_order = 7;
  int64 created_at_ms = 8;
  int64 updated_at_ms = 9;
  string item_type = 10;
  string wallet_asset_type = 11;
  int64 wallet_asset_amount = 12;
}

message ResourceGroup {
  string app_code = 1;
  int64 group_id = 2;
  string group_code = 3;
  string name = 4;
  string status = 5;
  string description = 6;
  int32 sort_order = 7;
  repeated ResourceGroupItem items = 8;
  int64 created_by_user_id = 9;
  int64 updated_by_user_id = 10;
  int64 created_at_ms = 11;
  int64 updated_at_ms = 12;
}

message GiftConfig {
  string app_code = 1;
  string gift_id = 2;
  int64 resource_id = 3;
  Resource resource = 4;
  string status = 5;
  string name = 6;
  int32 sort_order = 7;
  string presentation_json = 8;
  string price_version = 9;
  int64 coin_price = 10;
  // gift_point_amount 是历史字段；送礼结算不再读取该值，新写入固定为 0。
  int64 gift_point_amount = 11;
  int64 heat_value = 12;
  int64 created_by_user_id = 13;
  int64 updated_by_user_id = 14;
  int64 created_at_ms = 15;
  int64 updated_at_ms = 16;
  repeated int64 region_ids = 17;
  string gift_type_code = 18;
  string charge_asset_type = 19;
  int64 effective_from_ms = 20;
  int64 effective_to_ms = 21;
  repeated string effect_types = 22;
  string cp_relation_type = 23;
}

message GiftTypeConfig {
  string app_code = 1;
  string type_code = 2;
  string name = 3;
  string tab_key = 4;
  string status = 5;
  int32 sort_order = 6;
  int64 created_by_user_id = 7;
  int64 updated_by_user_id = 8;
  int64 created_at_ms = 9;
  int64 updated_at_ms = 10;
}

message ResourceShopItem {
  string app_code = 1;
  int64 shop_item_id = 2;
  int64 resource_id = 3;
  Resource resource = 4;
  string status = 5;
  int32 duration_days = 6;
  string price_type = 7;
  int64 coin_price = 8;
  int64 effective_from_ms = 9;
  int64 effective_to_ms = 10;
  int32 sort_order = 11;
  int64 created_by_user_id = 12;
  int64 updated_by_user_id = 13;
  int64 created_at_ms = 14;
  int64 updated_at_ms = 15;
}

message UserResourceEntitlement {
  string app_code = 1;
  string entitlement_id = 2;
  int64 user_id = 3;
  int64 resource_id = 4;
  Resource resource = 5;
  string status = 6;
  int64 quantity = 7;
  int64 remaining_quantity = 8;
  int64 effective_at_ms = 9;
  int64 expires_at_ms = 10;
  string source_grant_id = 11;
  int64 created_at_ms = 12;
  int64 updated_at_ms = 13;
  bool equipped = 14;
}

message ResourceGrantItem {
  int64 grant_item_id = 1;
  string grant_id = 2;
  int64 resource_id = 3;
  string resource_snapshot_json = 4;
  int64 quantity = 5;
  int64 duration_ms = 6;
  string result_type = 7;
  string wallet_transaction_id = 8;
  string entitlement_id = 9;
  int64 created_at_ms = 10;
}

message ResourceGrant {
  string app_code = 1;
  string grant_id = 2;
  string command_id = 3;
  int64 target_user_id = 4;
  string grant_source = 5;
  string grant_subject_type = 6;
  string grant_subject_id = 7;
  string status = 8;
  string reason = 9;
  int64 operator_user_id = 10;
  repeated ResourceGrantItem items = 11;
  int64 created_at_ms = 12;
  int64 updated_at_ms = 13;
  int64 revoked_at_ms = 14;
  int64 revoked_by_user_id = 15;
  string revoke_reason = 16;
}

message ResourceGroupItemInput {
  int64 resource_id = 1;
  int64 quantity = 2;
  int64 duration_ms = 3;
  int32 sort_order = 4;
  string item_type = 5;
  string wallet_asset_type = 6;
  int64 wallet_asset_amount = 7;
}

message ListResourcesRequest {
  string request_id = 1;
  string app_code = 2;
  string resource_type = 3;
  string status = 4;
  string keyword = 5;
  int32 page = 6;
  int32 page_size = 7;
  bool active_only = 8;
  bool manager_grant_only = 9;
}

message ListResourcesResponse {
  repeated Resource resources = 1;
  int64 total = 2;
}

message GetResourceRequest {
  string request_id = 1;
  string app_code = 2;
  int64 resource_id = 3;
}

message GetResourceResponse {
  Resource resource = 1;
}

message CreateResourceRequest {
  string request_id = 1;
  string app_code = 2;
  string resource_code = 3;
  string resource_type = 4;
  string name = 5;
  string status = 6;
  bool grantable = 7;
  string grant_strategy = 8;
  string wallet_asset_type = 9;
  int64 wallet_asset_amount = 10;
  repeated string usage_scopes = 11;
  string asset_url = 12;
  string preview_url = 13;
  string animation_url = 14;
  string metadata_json = 15;
  int32 sort_order = 16;
  int64 operator_user_id = 17;
  optional bool manager_grant_enabled = 18;
  string price_type = 19;
  int64 coin_price = 20;
  // gift_point_amount 是历史字段；服务端忽略请求值并固定写入 0。
  int64 gift_point_amount = 21;
}

message UpdateResourceRequest {
  string request_id = 1;
  string app_code = 2;
  int64 resource_id = 3;
  string resource_code = 4;
  string resource_type = 5;
  string name = 6;
  string status = 7;
  bool grantable = 8;
  string grant_strategy = 9;
  string wallet_asset_type = 10;
  int64 wallet_asset_amount = 11;
  repeated string usage_scopes = 12;
  string asset_url = 13;
  string preview_url = 14;
  string animation_url = 15;
  string metadata_json = 16;
  int32 sort_order = 17;
  int64 operator_user_id = 18;
  optional bool manager_grant_enabled = 19;
  string price_type = 20;
  int64 coin_price = 21;
  // gift_point_amount 是历史字段；服务端忽略请求值并固定写入 0。
  int64 gift_point_amount = 22;
}

message SetResourceStatusRequest {
  string request_id = 1;
  string app_code = 2;
  int64 resource_id = 3;
  string status = 4;
  int64 operator_user_id = 5;
}

message ResourceResponse {
  Resource resource = 1;
}

message ListResourceGroupsRequest {
  string request_id = 1;
  string app_code = 2;
  string status = 3;
  string keyword = 4;
  int32 page = 5;
  int32 page_size = 6;
  bool active_only = 7;
}

message ListResourceGroupsResponse {
  repeated ResourceGroup groups = 1;
  int64 total = 2;
}

message GetResourceGroupRequest {
  string request_id = 1;
  string app_code = 2;
  int64 group_id = 3;
}

message GetResourceGroupResponse {
  ResourceGroup group = 1;
}

message CreateResourceGroupRequest {
  string request_id = 1;
  string app_code = 2;
  string group_code = 3;
  string name = 4;
  string status = 5;
  string description = 6;
  int32 sort_order = 7;
  repeated ResourceGroupItemInput items = 8;
  int64 operator_user_id = 9;
}

message UpdateResourceGroupRequest {
  string request_id = 1;
  string app_code = 2;
  int64 group_id = 3;
  string group_code = 4;
  string name = 5;
  string status = 6;
  string description = 7;
  int32 sort_order = 8;
  repeated ResourceGroupItemInput items = 9;
  int64 operator_user_id = 10;
}

message SetResourceGroupStatusRequest {
  string request_id = 1;
  string app_code = 2;
  int64 group_id = 3;
  string status = 4;
  int64 operator_user_id = 5;
}

message ResourceGroupResponse {
  ResourceGroup group = 1;
}

message ListGiftConfigsRequest {
  string request_id = 1;
  string app_code = 2;
  string status = 3;
  string keyword = 4;
  int32 page = 5;
  int32 page_size = 6;
  bool active_only = 7;
  int64 region_id = 8;
  bool filter_region = 9;
  string gift_type_code = 10;
}

message ListGiftConfigsResponse {
  repeated GiftConfig gifts = 1;
  int64 total = 2;
}

message ListGiftTypeConfigsRequest {
  string request_id = 1;
  string app_code = 2;
  string status = 3;
  bool active_only = 4;
}

message ListGiftTypeConfigsResponse {
  repeated GiftTypeConfig gift_types = 1;
}

message UpsertGiftTypeConfigRequest {
  string request_id = 1;
  string app_code = 2;
  string type_code = 3;
  string name = 4;
  string tab_key = 5;
  string status = 6;
  int32 sort_order = 7;
  int64 operator_user_id = 8;
}

message GiftTypeConfigResponse {
  GiftTypeConfig gift_type = 1;
}

message CreateGiftConfigRequest {
  string request_id = 1;
  string app_code = 2;
  string gift_id = 3;
  int64 resource_id = 4;
  string status = 5;
  string name = 6;
  int32 sort_order = 7;
  string presentation_json = 8;
  string price_version = 9;
  int64 coin_price = 10;
  // gift_point_amount 是历史字段；服务端忽略请求值并固定写入 0。
  int64 gift_point_amount = 11;
  int64 heat_value = 12;
  int64 effective_at_ms = 13;
  int64 operator_user_id = 14;
  repeated int64 region_ids = 15;
  string gift_type_code = 16;
  string charge_asset_type = 17;
  int64 effective_from_ms = 18;
  int64 effective_to_ms = 19;
  repeated string effect_types = 20;
  string cp_relation_type = 21;
}

message UpdateGiftConfigRequest {
  string request_id = 1;
  string app_code = 2;
  string gift_id = 3;
  int64 resource_id = 4;
  string status = 5;
  string name = 6;
  int32 sort_order = 7;
  string presentation_json = 8;
  string price_version = 9;
  int64 coin_price = 10;
  // gift_point_amount 是历史字段；服务端忽略请求值并固定写入 0。
  int64 gift_point_amount = 11;
  int64 heat_value = 12;
  int64 effective_at_ms = 13;
  int64 operator_user_id = 14;
  repeated int64 region_ids = 15;
  string gift_type_code = 16;
  string charge_asset_type = 17;
  int64 effective_from_ms = 18;
  int64 effective_to_ms = 19;
  repeated string effect_types = 20;
  string cp_relation_type = 21;
}

message SetGiftConfigStatusRequest {
  string request_id = 1;
  string app_code = 2;
  string gift_id = 3;
  string status = 4;
  int64 operator_user_id = 5;
}

message DeleteGiftConfigRequest {
  string request_id = 1;
  string app_code = 2;
  string gift_id = 3;
  int64 operator_user_id = 4;
}

message GiftConfigResponse {
  GiftConfig gift = 1;
}

message GrantResourceRequest {
  string command_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 resource_id = 4;
  int64 quantity = 5;
  int64 duration_ms = 6;
  string reason = 7;
  int64 operator_user_id = 8;
  string grant_source = 9;
}

message GrantResourceGroupRequest {
  string command_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 group_id = 4;
  string reason = 5;
  int64 operator_user_id = 6;
  string grant_source = 7;
}

message RevokeResourceGrantRequest {
  string request_id = 1;
  string app_code = 2;
  string grant_id = 3;
  string reason = 4;
  int64 operator_user_id = 5;
}

message ResourceGrantResponse {
  ResourceGrant grant = 1;
}

message ListUserResourcesRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  string resource_type = 4;
  bool active_only = 5;
}

message ListUserResourcesResponse {
  repeated UserResourceEntitlement resources = 1;
}

message EquipUserResourceRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  int64 resource_id = 4;
  string entitlement_id = 5;
}

message EquipUserResourceResponse {
  UserResourceEntitlement resource = 1;
}

message UnequipUserResourceRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  string resource_type = 4;
}

message UnequipUserResourceResponse {
  string resource_type = 1;
  bool unequipped = 2;
  int64 updated_at_ms = 3;
}

message BatchGetUserEquippedResourcesRequest {
  string request_id = 1;
  string app_code = 2;
  repeated int64 user_ids = 3;
  repeated string resource_types = 4;
}

message UserEquippedResources {
  int64 user_id = 1;
  repeated UserResourceEntitlement resources = 2;
}

message BatchGetUserEquippedResourcesResponse {
  repeated UserEquippedResources users = 1;
}

message ListResourceGrantsRequest {
  string request_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  string status = 4;
  int32 page = 5;
  int32 page_size = 6;
}

message ListResourceGrantsResponse {
  repeated ResourceGrant grants = 1;
  int64 total = 2;
}

message ResourceShopItemInput {
  int64 shop_item_id = 1;
  int64 resource_id = 2;
  string status = 3;
  int32 duration_days = 4;
  int64 effective_from_ms = 5;
  int64 effective_to_ms = 6;
  int32 sort_order = 7;
}

message ListResourceShopItemsRequest {
  string request_id = 1;
  string app_code = 2;
  string resource_type = 3;
  string status = 4;
  string keyword = 5;
  int32 page = 6;
  int32 page_size = 7;
  bool active_only = 8;
}

message ListResourceShopItemsResponse {
  repeated ResourceShopItem items = 1;
  int64 total = 2;
}

message UpsertResourceShopItemsRequest {
  string request_id = 1;
  string app_code = 2;
  repeated ResourceShopItemInput items = 3;
  int64 operator_user_id = 4;
}

message UpsertResourceShopItemsResponse {
  repeated ResourceShopItem items = 1;
}

message SetResourceShopItemStatusRequest {
  string request_id = 1;
  string app_code = 2;
  int64 shop_item_id = 3;
  string status = 4;
  int64 operator_user_id = 5;
}

message ResourceShopItemResponse {
  ResourceShopItem item = 1;
}

message PurchaseResourceShopItemRequest {
  string command_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  int64 shop_item_id = 4;
}

message PurchaseResourceShopItemResponse {
  string order_id = 1;
  string transaction_id = 2;
  string resource_grant_id = 3;
  ResourceShopItem shop_item = 4;
  UserResourceEntitlement resource = 5;
  AssetBalance balance = 6;
  int64 coin_spent = 7;
}

message RechargeBill {
  string app_code = 1;
  string transaction_id = 2;
  string command_id = 3;
  string recharge_type = 4;
  string status = 5;
  string external_ref = 6;
  int64 user_id = 7;
  int64 seller_user_id = 8;
  int64 seller_region_id = 9;
  int64 target_region_id = 10;
  int64 policy_id = 11;
  string policy_version = 12;
  string currency_code = 13;
  int64 coin_amount = 14;
  int64 usd_minor_amount = 15;
  int64 exchange_coin_amount = 16;
  int64 exchange_usd_minor_amount = 17;
  int64 created_at_ms = 18;
}

message ListRechargeBillsRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  int64 seller_user_id = 4;
  int64 region_id = 5;
  string recharge_type = 6;
  string status = 7;
  string keyword = 8;
  int64 start_at_ms = 9;
  int64 end_at_ms = 10;
  int32 page = 11;
  int32 page_size = 12;
}

message ListRechargeBillsResponse {
  repeated RechargeBill bills = 1;
  int64 total = 2;
}

// WalletFeatureFlags 是我的页和钱包首页使用的操作开关，来源属于 wallet-service。
message WalletFeatureFlags {
  bool recharge_enabled = 1;
  bool diamond_exchange_enabled = 2;
}

message GetWalletOverviewRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
}

message GetWalletOverviewResponse {
  repeated AssetBalance balances = 1;
  WalletFeatureFlags feature_flags = 2;
}

// WalletValueSummary 是我的页钱包价值展示的轻量投影，只返回首屏展示需要的金币余额。
message WalletValueSummary {
  int64 coin_amount = 1;
  int64 updated_at_ms = 2;
}

message GetWalletValueSummaryRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
}

message GetWalletValueSummaryResponse {
  WalletValueSummary summary = 1;
}

// GiftWallItem 是用户礼物墙按礼物类型聚合后的当前投影。
message GiftWallItem {
  string gift_id = 1;
  string gift_name = 2;
  int64 resource_id = 3;
  Resource resource = 4;
  string resource_snapshot_json = 5;
  string gift_type_code = 6;
  string presentation_json = 7;
  int64 gift_count = 8;
  int64 total_value = 9;
  int64 total_coin_value = 10;
  int64 total_diamond_value = 11;
  // total_gift_point 是历史礼物墙字段；新送礼不再累加。
  int64 total_gift_point = 12;
  int64 total_heat_value = 13;
  string charge_asset_type = 14;
  string last_price_version = 15;
  int64 first_received_at_ms = 16;
  int64 last_received_at_ms = 17;
  int32 sort_order = 18;
}

message GetUserGiftWallRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
}

message GetUserGiftWallResponse {
  repeated GiftWallItem items = 1;
  int64 gift_kind_count = 2;
  int64 gift_total_count = 3;
  int64 total_value = 4;
  int64 total_coin_value = 5;
  int64 total_diamond_value = 6;
  // total_gift_point 是历史礼物墙汇总字段；新送礼不再累加。
  int64 total_gift_point = 7;
  int64 total_heat_value = 8;
}

// RechargeProduct 是 App 充值页可展示的区域化充值档位。
message RechargeProduct {
  int64 product_id = 1;
  string product_code = 2;
  string channel = 3;
  string currency_code = 4;
  int64 coin_amount = 5;
  int64 amount_minor = 6;
  string policy_version = 7;
  bool enabled = 8;
  int32 sort_order = 9;
  string product_name = 10;
  string description = 11;
  string platform = 12;
  repeated int64 region_ids = 13;
  string resource_asset_type = 14;
  int64 amount_micro = 15;
  int64 created_by_user_id = 16;
  int64 updated_by_user_id = 17;
  int64 created_at_ms = 18;
  int64 updated_at_ms = 19;
  string app_code = 20;
  string status = 21;
  // audience_type 区分 H5 普通用户档位和币商档位；旧 App 内购默认 normal。
  string audience_type = 22;
}

message ListRechargeProductsRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  int64 region_id = 4;
  // platform 来自 gateway 解析的 App 平台请求头；为空时返回该区域全部已上架商品。
  string platform = 5;
  // audience_type 只用于 H5 站外充值；App 旧入口为空时按 normal 兼容。
  string audience_type = 6;
}

message ListRechargeProductsResponse {
  repeated RechargeProduct products = 1;
  repeated string channels = 2;
}

message ConfirmGooglePaymentRequest {
  string request_id = 1;
  string app_code = 2;
  string command_id = 3;
  int64 user_id = 4;
  int64 region_id = 5;
  int64 product_id = 6;
  string product_code = 7;
  string package_name = 8;
  string purchase_token = 9;
  string order_id = 10;
  int64 purchase_time_ms = 11;
  // country_id 由 gateway 从 user-service 当前用户资料注入，用于充值事实按真实国家进入 BI。
  int64 country_id = 12;
}

message ConfirmGooglePaymentResponse {
  string payment_order_id = 1;
  string transaction_id = 2;
  string status = 3;
  int64 product_id = 4;
  string product_code = 5;
  int64 coin_amount = 6;
  AssetBalance balance = 7;
  bool idempotent_replay = 8;
  string consume_state = 9;
}

// ListAdminRechargeProductsRequest 是后台内购配置列表查询，不参与用户充值主链路。
message ListAdminRechargeProductsRequest {
  string request_id = 1;
  string app_code = 2;
  string status = 3;
  string platform = 4;
  int64 region_id = 5;
  string keyword = 6;
  int32 page = 7;
  int32 page_size = 8;
  string audience_type = 9;
}

message ListAdminRechargeProductsResponse {
  repeated RechargeProduct products = 1;
  int64 total = 2;
}

// CreateRechargeProductRequest 配置一个 App 内购商品；首版资源资产固定为 COIN。
message CreateRechargeProductRequest {
  string request_id = 1;
  string app_code = 2;
  int64 amount_micro = 3;
  int64 coin_amount = 4;
  string product_name = 5;
  string description = 6;
  string platform = 7;
  repeated int64 region_ids = 8;
  bool enabled = 9;
  int64 operator_user_id = 10;
  string audience_type = 11;
}

message UpdateRechargeProductRequest {
  string request_id = 1;
  string app_code = 2;
  int64 product_id = 3;
  int64 amount_micro = 4;
  int64 coin_amount = 5;
  string product_name = 6;
  string description = 7;
  string platform = 8;
  repeated int64 region_ids = 9;
  bool enabled = 10;
  int64 operator_user_id = 11;
  string audience_type = 12;
}

message DeleteRechargeProductRequest {
  string request_id = 1;
  string app_code = 2;
  int64 product_id = 3;
  int64 operator_user_id = 4;
}

message RechargeProductResponse {
  RechargeProduct product = 1;
}

message DeleteRechargeProductResponse {
  bool deleted = 1;
}

// ThirdPartyPaymentMethod 是后台和 H5 共用的三方支付方式配置快照。
message ThirdPartyPaymentMethod {
  int64 method_id = 1;
  string app_code = 2;
  string provider_code = 3;
  string provider_name = 4;
  string country_code = 5;
  string country_name = 6;
  string currency_code = 7;
  string pay_way = 8;
  string pay_type = 9;
  string method_name = 10;
  string logo_url = 11;
  string status = 12;
  string usd_to_currency_rate = 13;
  int32 sort_order = 14;
  int64 created_at_ms = 15;
  int64 updated_at_ms = 16;
}

message ThirdPartyPaymentChannel {
  string app_code = 1;
  string provider_code = 2;
  string provider_name = 3;
  string status = 4;
  int32 sort_order = 5;
  repeated ThirdPartyPaymentMethod methods = 6;
}

message ListThirdPartyPaymentChannelsRequest {
  string request_id = 1;
  string app_code = 2;
  string provider_code = 3;
  string status = 4;
  bool include_disabled_methods = 5;
}

message ListThirdPartyPaymentChannelsResponse {
  repeated ThirdPartyPaymentChannel channels = 1;
}

message SetThirdPartyPaymentMethodStatusRequest {
  string request_id = 1;
  string app_code = 2;
  int64 method_id = 3;
  bool enabled = 4;
  int64 operator_user_id = 5;
}

message ThirdPartyPaymentMethodResponse {
  ThirdPartyPaymentMethod method = 1;
}

message UpdateThirdPartyPaymentRateRequest {
  string request_id = 1;
  string app_code = 2;
  int64 method_id = 3;
  string usd_to_currency_rate = 4;
  int64 operator_user_id = 5;
}

message ThirdPartyPaymentMethodSyncIssue {
  string country_code = 1;
  string currency_code = 2;
  string code = 3;
  string message = 4;
}

message SyncThirdPartyPaymentMethodsRequest {
  string request_id = 1;
  string app_code = 2;
  string provider_code = 3;
  int64 operator_user_id = 4;
}

message SyncThirdPartyPaymentMethodsResponse {
  string provider_code = 1;
  int32 scanned_country_count = 2;
  int32 fetched_country_count = 3;
  int32 created_count = 4;
  int32 updated_count = 5;
  int32 skipped_count = 6;
  repeated ThirdPartyPaymentMethodSyncIssue issues = 7;
}

message H5RechargeOptionsRequest {
  string request_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 target_region_id = 4;
  string target_country_code = 5;
  string audience_type = 6;
}

message H5RechargeOptionsResponse {
  repeated RechargeProduct products = 1;
  repeated ThirdPartyPaymentMethod payment_methods = 2;
  bool usdt_trc20_enabled = 3;
  string usdt_trc20_address = 4;
}

message ExternalRechargeOrder {
  string order_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 target_region_id = 4;
  string target_country_code = 5;
  string audience_type = 6;
  int64 product_id = 7;
  string product_name = 8;
  int64 coin_amount = 9;
  int64 usd_minor_amount = 10;
  string provider_code = 11;
  int64 payment_method_id = 12;
  string country_code = 13;
  string currency_code = 14;
  int64 provider_amount_minor = 15;
  string pay_way = 16;
  string pay_type = 17;
  string pay_url = 18;
  string provider_order_id = 19;
  string tx_hash = 20;
  string receive_address = 21;
  string status = 22;
  string failure_reason = 23;
  string transaction_id = 24;
  int64 created_at_ms = 25;
  int64 updated_at_ms = 26;
  bool idempotent_replay = 27;
  // target_country_id 是下单时目标用户国家快照，支付回调入账直接复用，避免异步回调再查用户主数据。
  int64 target_country_id = 28;
}

message CreateH5RechargeOrderRequest {
  string request_id = 1;
  string app_code = 2;
  string command_id = 3;
  int64 target_user_id = 4;
  int64 target_region_id = 5;
  string target_country_code = 6;
  string audience_type = 7;
  int64 product_id = 8;
  string provider_code = 9;
  int64 payment_method_id = 10;
  string return_url = 11;
  string notify_url = 12;
  string client_ip = 13;
  string language = 14;
  // payer_name / payer_account 来自 gateway 重新解析的目标用户资料，不接受 H5 前端自报。
  string payer_name = 15;
  string payer_account = 16;
  string payer_email = 17;
  // target_country_id 由 gateway 从 user-service 解析目标用户，不接受 H5 前端自报。
  int64 target_country_id = 18;
}

message CreateTemporaryRechargeOrderRequest {
  string request_id = 1;
  string app_code = 2;
  string command_id = 3;
  int64 coin_amount = 4;
  int64 usd_minor_amount = 5;
  string provider_code = 6;
  int64 payment_method_id = 7;
  string return_url = 8;
  string notify_url = 9;
  string client_ip = 10;
  string language = 11;
  string payer_name = 12;
  string payer_account = 13;
  string payer_email = 14;
}

message GetTemporaryRechargeOrderRequest {
  string request_id = 1;
  string app_code = 2;
  string order_id = 3;
}

message ListTemporaryRechargeOrdersRequest {
  string request_id = 1;
  string app_code = 2;
  string status = 3;
  string provider_code = 4;
  string keyword = 5;
  int32 page = 6;
  int32 page_size = 7;
}

message ListTemporaryRechargeOrdersResponse {
  repeated ExternalRechargeOrder orders = 1;
  int64 total = 2;
}

message SubmitH5RechargeTxRequest {
  string request_id = 1;
  string app_code = 2;
  string order_id = 3;
  int64 target_user_id = 4;
  string tx_hash = 5;
}

message GetH5RechargeOrderRequest {
  string request_id = 1;
  string app_code = 2;
  string order_id = 3;
  int64 target_user_id = 4;
}

message H5RechargeOrderResponse {
  ExternalRechargeOrder order = 1;
}

message HandleMifapayNotifyRequest {
  string request_id = 1;
  string app_code = 2;
  string mer_account = 3;
  string data = 4;
  string sign = 5;
}

message HandleMifapayNotifyResponse {
  bool accepted = 1;
  string response_text = 2;
  string order_id = 3;
}

message HandleV5PayNotifyRequest {
  string request_id = 1;
  string app_code = 2;
  string raw_json = 3;
  map<string, string> fields = 4;
}

message HandleV5PayNotifyResponse {
  bool accepted = 1;
  string response_text = 2;
  string order_id = 3;
}

message DiamondExchangeRule {
  string exchange_type = 1;
  string from_asset_type = 2;
  string to_asset_type = 3;
  int64 from_amount = 4;
  int64 to_amount = 5;
  bool enabled = 6;
}

message GetDiamondExchangeConfigRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
}

message GetDiamondExchangeConfigResponse {
  repeated DiamondExchangeRule rules = 1;
}

// WalletTransaction 是用户钱包流水页使用的分录级投影。
message WalletTransaction {
  int64 entry_id = 1;
  string transaction_id = 2;
  string biz_type = 3;
  string asset_type = 4;
  int64 available_delta = 5;
  int64 frozen_delta = 6;
  int64 available_after = 7;
  int64 frozen_after = 8;
  int64 counterparty_user_id = 9;
  string room_id = 10;
  int64 created_at_ms = 11;
}

message ListWalletTransactionsRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  string asset_type = 4;
  int32 page = 5;
  int32 page_size = 6;
}

message ListWalletTransactionsResponse {
  repeated WalletTransaction transactions = 1;
  int64 total = 2;
}

message VipRewardItem {
  int64 resource_id = 1;
  string resource_code = 2;
  string resource_type = 3;
  string name = 4;
  int64 quantity = 5;
  int64 expires_at_ms = 6;
  string asset_url = 7;
  string preview_url = 8;
  string animation_url = 9;
}

message VipLevel {
  int32 level = 1;
  string name = 2;
  string status = 3;
  int64 price_coin = 4;
  int64 duration_ms = 5;
  int64 reward_resource_group_id = 6;
  repeated VipRewardItem reward_items = 7;
  bool can_purchase = 8;
  int32 sort_order = 9;
  bool recharge_gate_required = 10;
  int64 required_recharge_coin_amount = 11;
  int64 user_recharge_coin_amount = 12;
  string purchase_locked_reason = 13;
  int64 created_at_ms = 14;
  int64 updated_at_ms = 15;
}

message UserVip {
  int64 user_id = 1;
  int32 level = 2;
  string name = 3;
  bool active = 4;
  int64 started_at_ms = 5;
  int64 expires_at_ms = 6;
  int64 updated_at_ms = 7;
}

message ListVipPackagesRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
}

message ListVipPackagesResponse {
  UserVip current_vip = 1;
  repeated VipLevel packages = 2;
}

message GetMyVipRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
}

message GetMyVipResponse {
  UserVip vip = 1;
}

message PurchaseVipRequest {
  string command_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  int32 level = 4;
}

message PurchaseVipResponse {
  string order_id = 1;
  string transaction_id = 2;
  UserVip vip = 3;
  int64 coin_spent = 4;
  int64 coin_balance_after = 5;
  repeated VipRewardItem reward_items = 6;
}

message DebitCPBreakupFeeRequest {
  string command_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  string relationship_id = 4;
  string relation_type = 5;
  int64 amount = 6;
}

message DebitCPBreakupFeeResponse {
  string transaction_id = 1;
  int64 coin_spent = 2;
  int64 coin_balance_after = 3;
  AssetBalance balance = 4;
}

message DebitWheelDrawRequest {
  string command_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  string wheel_id = 4;
  int32 draw_count = 5;
  int64 amount = 6;
}

message DebitWheelDrawResponse {
  string transaction_id = 1;
  int64 coin_spent = 2;
  int64 coin_balance_after = 3;
  AssetBalance balance = 4;
}

message GrantVipRequest {
  string command_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int32 level = 4;
  string grant_source = 5;
  int64 operator_user_id = 6;
  string reason = 7;
}

message GrantVipResponse {
  string transaction_id = 1;
  UserVip vip = 2;
  repeated VipRewardItem reward_items = 3;
  int64 server_time_ms = 4;
}

message AdminVipLevelInput {
  int32 level = 1;
  string name = 2;
  string status = 3;
  int64 price_coin = 4;
  int64 duration_ms = 5;
  int64 reward_resource_group_id = 6;
  int32 sort_order = 7;
  int64 required_recharge_coin_amount = 8;
}

message ListAdminVipLevelsRequest {
  string request_id = 1;
  string app_code = 2;
}

message ListAdminVipLevelsResponse {
  repeated VipLevel levels = 1;
  int64 server_time_ms = 2;
}

message UpdateAdminVipLevelsRequest {
  string request_id = 1;
  string app_code = 2;
  repeated AdminVipLevelInput levels = 3;
  int64 operator_user_id = 4;
}

message UpdateAdminVipLevelsResponse {
  repeated VipLevel levels = 1;
  int64 server_time_ms = 2;
}

// CreditTaskRewardRequest 是 activity-service 领取任务奖励时调用的钱包入账命令。
message CreditTaskRewardRequest {
  string command_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 amount = 4;
  string task_type = 5;
  string task_id = 6;
  string cycle_key = 7;
  string reason = 8;
}

// CreditTaskRewardResponse 返回任务奖励入账流水和用户 COIN 账后余额。
message CreditTaskRewardResponse {
  string transaction_id = 1;
  AssetBalance balance = 2;
  int64 amount = 3;
  int64 granted_at_ms = 4;
}

// CreditLuckyGiftRewardRequest 是 activity-service 抽奖 outbox 补偿 worker 调用的钱包入账命令。
message CreditLuckyGiftRewardRequest {
  string command_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 amount = 4;
  string draw_id = 5;
  string room_id = 6;
  string gift_id = 7;
  string pool_id = 8;
  string reason = 9;
  int64 visible_region_id = 10;
  // country_id 是中奖用户所属国家，钱包 outbox 原样发布给统计服务，避免返奖只落到区域未知国家。
  int64 country_id = 11;
}

// CreditLuckyGiftRewardResponse 返回幸运礼物返奖入账流水和用户 COIN 账后余额。
message CreditLuckyGiftRewardResponse {
  string transaction_id = 1;
  AssetBalance balance = 2;
  int64 amount = 3;
  int64 granted_at_ms = 4;
}

// CreditWheelRewardRequest 是 activity-service 转盘金币奖品 outbox 调用的钱包入账命令。
message CreditWheelRewardRequest {
  string command_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 amount = 4;
  string draw_id = 5;
  string wheel_id = 6;
  string selected_tier_id = 7;
  string reason = 8;
  int64 visible_region_id = 9;
}

// CreditWheelRewardResponse 返回转盘金币奖品入账流水和用户 COIN 账后余额。
message CreditWheelRewardResponse {
  string transaction_id = 1;
  AssetBalance balance = 2;
  int64 amount = 3;
  int64 granted_at_ms = 4;
}

// CreditRoomTurnoverRewardRequest 是 activity-service 每周房间流水奖励结算后的金币入账命令。
message CreditRoomTurnoverRewardRequest {
  string command_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 amount = 4;
  string settlement_id = 5;
  string room_id = 6;
  int64 period_start_ms = 7;
  int64 period_end_ms = 8;
  int64 coin_spent = 9;
  int64 tier_id = 10;
  string tier_code = 11;
  string reason = 12;
}

// CreditRoomTurnoverRewardResponse 返回房间流水奖励入账流水和用户 COIN 账后余额。
message CreditRoomTurnoverRewardResponse {
  string transaction_id = 1;
  AssetBalance balance = 2;
  int64 amount = 3;
  int64 granted_at_ms = 4;
}

// CreditInviteActivityRewardRequest 是 activity-service 邀请活动达标后发起的 COIN 奖励入账命令。
message CreditInviteActivityRewardRequest {
  string command_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 amount = 4;
  string claim_id = 5;
  string reward_type = 6;
  int64 tier_id = 7;
  string tier_code = 8;
  string cycle_key = 9;
  int64 reached_value = 10;
  string reason = 11;
}

// CreditInviteActivityRewardResponse 返回邀请活动奖励入账流水和用户 COIN 账后余额。
message CreditInviteActivityRewardResponse {
  string transaction_id = 1;
  AssetBalance balance = 2;
  int64 amount = 3;
  int64 granted_at_ms = 4;
}

// CreditAgencyOpeningRewardRequest 是 activity-service 代理开业流水档位结算后的 COIN 入账命令。
message CreditAgencyOpeningRewardRequest {
  string command_id = 1;
  string app_code = 2;
  int64 target_user_id = 3;
  int64 amount = 4;
  string application_id = 5;
  string cycle_id = 6;
  int64 agency_id = 7;
  int32 rank_no = 8;
  int64 score_coins = 9;
  string reason = 10;
}

// CreditAgencyOpeningRewardResponse 返回代理开业奖励入账流水和用户 COIN 账后余额。
message CreditAgencyOpeningRewardResponse {
  string transaction_id = 1;
  AssetBalance balance = 2;
  int64 amount = 3;
  int64 granted_at_ms = 4;
}

// ApplyGameCoinChangeRequest 是 game-service 唯一可以调用的钱包游戏改账入口。
message ApplyGameCoinChangeRequest {
  string request_id = 1;
  string app_code = 2;
  string command_id = 3;
  int64 user_id = 4;
  string platform_code = 5;
  string game_id = 6;
  string provider_order_id = 7;
  string provider_round_id = 8;
  string op_type = 9;
  int64 coin_amount = 10;
  string room_id = 11;
  string request_hash = 12;
}

// ApplyGameCoinChangeResponse 返回游戏改账流水和用户 COIN 账后余额。
message ApplyGameCoinChangeResponse {
  string wallet_transaction_id = 1;
  int64 balance_after = 2;
  bool idempotent_replay = 3;
}

message RedPacketConfig {
  string app_code = 1;
  bool enabled = 2;
  repeated int32 count_tiers = 3;
  repeated int64 amount_tiers = 4;
  int32 delayed_open_seconds = 5;
  int32 expire_seconds = 6;
  int32 daily_send_limit = 7;
  int64 updated_by_admin_id = 8;
  int64 created_at_ms = 9;
  int64 updated_at_ms = 10;
  string rule_url = 11;
}

message RedPacketClaim {
  string app_code = 1;
  string claim_id = 2;
  string command_id = 3;
  string packet_id = 4;
  int64 user_id = 5;
  int64 amount = 6;
  string wallet_transaction_id = 7;
  string status = 8;
  string failure_reason = 9;
  int64 created_at_ms = 10;
  int64 updated_at_ms = 11;
}

message RedPacket {
  string app_code = 1;
  string packet_id = 2;
  string command_id = 3;
  int64 sender_user_id = 4;
  string room_id = 5;
  int64 region_id = 6;
  string packet_type = 7;
  int64 total_amount = 8;
  int32 packet_count = 9;
  int64 remaining_amount = 10;
  int32 remaining_count = 11;
  string status = 12;
  int64 open_at_ms = 13;
  int64 expires_at_ms = 14;
  int64 created_at_ms = 15;
  int64 updated_at_ms = 16;
  bool claimed_by_viewer = 17;
  int64 viewer_claim_amount = 18;
  repeated RedPacketClaim claims = 19;
  int64 refund_amount = 20;
  string refund_status = 21;
  int64 refunded_at_ms = 22;
}

message GetRedPacketConfigRequest {
  string request_id = 1;
  string app_code = 2;
}

message GetRedPacketConfigResponse {
  RedPacketConfig config = 1;
  int64 server_time_ms = 2;
}

message UpdateRedPacketConfigRequest {
  string request_id = 1;
  string app_code = 2;
  bool enabled = 3;
  repeated int32 count_tiers = 4;
  repeated int64 amount_tiers = 5;
  int32 delayed_open_seconds = 6;
  int32 expire_seconds = 7;
  int32 daily_send_limit = 8;
  int64 operator_user_id = 9;
  string rule_url = 10;
}

message UpdateRedPacketConfigResponse {
  RedPacketConfig config = 1;
  int64 server_time_ms = 2;
}

message CreateRedPacketRequest {
  string request_id = 1;
  string app_code = 2;
  string command_id = 3;
  int64 sender_user_id = 4;
  string room_id = 5;
  int64 region_id = 6;
  string packet_type = 7;
  int64 total_amount = 8;
  int32 packet_count = 9;
}

message CreateRedPacketResponse {
  RedPacket packet = 1;
  int64 balance_after = 2;
  int64 server_time_ms = 3;
}

message ClaimRedPacketRequest {
  string request_id = 1;
  string app_code = 2;
  string command_id = 3;
  string packet_id = 4;
  int64 user_id = 5;
}

message ClaimRedPacketResponse {
  RedPacketClaim claim = 1;
  int64 balance_after = 2;
  int64 server_time_ms = 3;
  RedPacket packet = 4;
}

message ListRedPacketsRequest {
  string request_id = 1;
  string app_code = 2;
  string room_id = 3;
  int64 sender_user_id = 4;
  int64 region_id = 5;
  string packet_type = 6;
  string status = 7;
  int64 viewer_user_id = 8;
  int64 start_at_ms = 9;
  int64 end_at_ms = 10;
  int32 page = 11;
  int32 page_size = 12;
}

message ListRedPacketsResponse {
  repeated RedPacket packets = 1;
  int64 total = 2;
  int64 server_time_ms = 3;
}

message GetRedPacketRequest {
  string request_id = 1;
  string app_code = 2;
  string packet_id = 3;
  int64 viewer_user_id = 4;
  bool include_claims = 5;
}

message GetRedPacketResponse {
  RedPacket packet = 1;
  int64 server_time_ms = 2;
}

message ExpireRedPacketsRequest {
  string request_id = 1;
  string app_code = 2;
  int32 batch_size = 3;
}

message ExpireRedPacketsResponse {
  int32 expired_count = 1;
  int64 refunded_amount = 2;
  int64 server_time_ms = 3;
}

message RetryRedPacketRefundRequest {
  string request_id = 1;
  string app_code = 2;
  string packet_id = 3;
  int64 operator_user_id = 4;
}

message RetryRedPacketRefundResponse {
  RedPacket packet = 1;
  int64 refunded_amount = 2;
  int64 server_time_ms = 3;
}

// CronBatchRequest 是 cron-service 触发 wallet-service 后台批处理的统一请求。
message CronBatchRequest {
  string request_id = 1;
  string app_code = 2;
  string run_id = 3;
  string worker_id = 4;
  int32 batch_size = 5;
  int64 lock_ttl_ms = 6;
  // trigger_mode 为空时由 wallet-service 按 automatic 处理；后台手动结算显式传 manual。
  string trigger_mode = 7;
  // cycle_key 为空时由 wallet-service 按当前 UTC 月处理；后台手动补结可指定周期。
  string cycle_key = 8;
  // user_ids 为空表示批处理扫描全部候选；后台手动结算只传已勾选主播。
  repeated int64 user_ids = 9;
  // settlement_role 为空时结算完整 Host/Agency 权益；后台人工入口可传 host 或 agency 拆分钱包。
  string settlement_role = 10;
}

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

message ResourceShopPurchaseOrder {
  string app_code = 1;
  string order_id = 2;
  string command_id = 3;
  int64 user_id = 4;
  int64 shop_item_id = 5;
  int64 resource_id = 6;
  Resource resource = 7;
  int32 duration_days = 8;
  int64 price_coin = 9;
  string status = 10;
  string wallet_transaction_id = 11;
  string resource_grant_id = 12;
  string entitlement_id = 13;
  int64 created_at_ms = 14;
  int64 updated_at_ms = 15;
}

message ListResourceShopPurchaseOrdersRequest {
  string request_id = 1;
  string app_code = 2;
  int64 user_id = 3;
  string resource_type = 4;
  string status = 5;
  string keyword = 6;
  int32 page = 7;
  int32 page_size = 8;
}

message ListResourceShopPurchaseOrdersResponse {
  repeated ResourceShopPurchaseOrder orders = 1;
  int64 total = 2;
}

// WalletCronService 只给 cron-service 调用；账务状态仍由 wallet-service owner 修改。
service WalletCronService {
  rpc ProcessHostSalaryDailySettlementBatch(CronBatchRequest) returns (CronBatchResponse);
  rpc ProcessHostSalaryHalfMonthSettlementBatch(CronBatchRequest) returns (CronBatchResponse);
  rpc ProcessHostSalaryMonthEndBatch(CronBatchRequest) returns (CronBatchResponse);
}

// WalletService 是内部账务 gRPC 边界，外部 HTTP 入口仍由 gateway-service 承载。
service WalletService {
  rpc DebitGift(DebitGiftRequest) returns (DebitGiftResponse);
  rpc DebitDirectGift(DebitDirectGiftRequest) returns (DebitGiftResponse);
  rpc BatchDebitGift(BatchDebitGiftRequest) returns (BatchDebitGiftResponse);
  rpc DebitRobotGift(DebitRobotGiftRequest) returns (DebitGiftResponse);
  rpc GetBalances(GetBalancesRequest) returns (GetBalancesResponse);
  rpc GetActiveHostSalaryPolicy(GetActiveHostSalaryPolicyRequest) returns (GetActiveHostSalaryPolicyResponse);
  rpc GetHostSalaryProgress(GetHostSalaryProgressRequest) returns (GetHostSalaryProgressResponse);
  rpc AdminCreditAsset(AdminCreditAssetRequest) returns (AdminCreditAssetResponse);
  rpc AdminCreditCoinSellerStock(AdminCreditCoinSellerStockRequest) returns (AdminCreditCoinSellerStockResponse);
  rpc TransferCoinFromSeller(TransferCoinFromSellerRequest) returns (TransferCoinFromSellerResponse);
  rpc ListCoinSellerSalaryExchangeRateTiers(ListCoinSellerSalaryExchangeRateTiersRequest) returns (ListCoinSellerSalaryExchangeRateTiersResponse);
  rpc ExchangeSalaryToCoin(ExchangeSalaryToCoinRequest) returns (ExchangeSalaryToCoinResponse);
  rpc TransferSalaryToCoinSeller(TransferSalaryToCoinSellerRequest) returns (TransferSalaryToCoinSellerResponse);
  rpc ListResources(ListResourcesRequest) returns (ListResourcesResponse);
  rpc GetResource(GetResourceRequest) returns (GetResourceResponse);
  rpc CreateResource(CreateResourceRequest) returns (ResourceResponse);
  rpc UpdateResource(UpdateResourceRequest) returns (ResourceResponse);
  rpc SetResourceStatus(SetResourceStatusRequest) returns (ResourceResponse);
  rpc ListResourceGroups(ListResourceGroupsRequest) returns (ListResourceGroupsResponse);
  rpc GetResourceGroup(GetResourceGroupRequest) returns (GetResourceGroupResponse);
  rpc CreateResourceGroup(CreateResourceGroupRequest) returns (ResourceGroupResponse);
  rpc UpdateResourceGroup(UpdateResourceGroupRequest) returns (ResourceGroupResponse);
  rpc SetResourceGroupStatus(SetResourceGroupStatusRequest) returns (ResourceGroupResponse);
  rpc ListGiftConfigs(ListGiftConfigsRequest) returns (ListGiftConfigsResponse);
  rpc ListGiftTypeConfigs(ListGiftTypeConfigsRequest) returns (ListGiftTypeConfigsResponse);
  rpc CreateGiftConfig(CreateGiftConfigRequest) returns (GiftConfigResponse);
  rpc UpdateGiftConfig(UpdateGiftConfigRequest) returns (GiftConfigResponse);
  rpc SetGiftConfigStatus(SetGiftConfigStatusRequest) returns (GiftConfigResponse);
  rpc DeleteGiftConfig(DeleteGiftConfigRequest) returns (GiftConfigResponse);
  rpc UpsertGiftTypeConfig(UpsertGiftTypeConfigRequest) returns (GiftTypeConfigResponse);
  rpc GrantResource(GrantResourceRequest) returns (ResourceGrantResponse);
  rpc GrantResourceGroup(GrantResourceGroupRequest) returns (ResourceGrantResponse);
  rpc RevokeResourceGrant(RevokeResourceGrantRequest) returns (ResourceGrantResponse);
  rpc ListUserResources(ListUserResourcesRequest) returns (ListUserResourcesResponse);
  rpc EquipUserResource(EquipUserResourceRequest) returns (EquipUserResourceResponse);
  rpc UnequipUserResource(UnequipUserResourceRequest) returns (UnequipUserResourceResponse);
  rpc BatchGetUserEquippedResources(BatchGetUserEquippedResourcesRequest) returns (BatchGetUserEquippedResourcesResponse);
  rpc ListResourceGrants(ListResourceGrantsRequest) returns (ListResourceGrantsResponse);
  rpc ListResourceShopItems(ListResourceShopItemsRequest) returns (ListResourceShopItemsResponse);
  rpc UpsertResourceShopItems(UpsertResourceShopItemsRequest) returns (UpsertResourceShopItemsResponse);
  rpc SetResourceShopItemStatus(SetResourceShopItemStatusRequest) returns (ResourceShopItemResponse);
  rpc ListResourceShopPurchaseOrders(ListResourceShopPurchaseOrdersRequest) returns (ListResourceShopPurchaseOrdersResponse);
  rpc PurchaseResourceShopItem(PurchaseResourceShopItemRequest) returns (PurchaseResourceShopItemResponse);
  rpc ListRechargeBills(ListRechargeBillsRequest) returns (ListRechargeBillsResponse);
  rpc GetWalletOverview(GetWalletOverviewRequest) returns (GetWalletOverviewResponse);
  rpc GetWalletValueSummary(GetWalletValueSummaryRequest) returns (GetWalletValueSummaryResponse);
  rpc GetUserGiftWall(GetUserGiftWallRequest) returns (GetUserGiftWallResponse);
  rpc ListRechargeProducts(ListRechargeProductsRequest) returns (ListRechargeProductsResponse);
  rpc ConfirmGooglePayment(ConfirmGooglePaymentRequest) returns (ConfirmGooglePaymentResponse);
  rpc ListAdminRechargeProducts(ListAdminRechargeProductsRequest) returns (ListAdminRechargeProductsResponse);
  rpc CreateRechargeProduct(CreateRechargeProductRequest) returns (RechargeProductResponse);
  rpc UpdateRechargeProduct(UpdateRechargeProductRequest) returns (RechargeProductResponse);
  rpc DeleteRechargeProduct(DeleteRechargeProductRequest) returns (DeleteRechargeProductResponse);
  rpc ListThirdPartyPaymentChannels(ListThirdPartyPaymentChannelsRequest) returns (ListThirdPartyPaymentChannelsResponse);
  rpc SetThirdPartyPaymentMethodStatus(SetThirdPartyPaymentMethodStatusRequest) returns (ThirdPartyPaymentMethodResponse);
  rpc UpdateThirdPartyPaymentRate(UpdateThirdPartyPaymentRateRequest) returns (ThirdPartyPaymentMethodResponse);
  rpc SyncThirdPartyPaymentMethods(SyncThirdPartyPaymentMethodsRequest) returns (SyncThirdPartyPaymentMethodsResponse);
  rpc ListH5RechargeOptions(H5RechargeOptionsRequest) returns (H5RechargeOptionsResponse);
  rpc CreateH5RechargeOrder(CreateH5RechargeOrderRequest) returns (H5RechargeOrderResponse);
  rpc CreateTemporaryRechargeOrder(CreateTemporaryRechargeOrderRequest) returns (H5RechargeOrderResponse);
  rpc GetTemporaryRechargeOrder(GetTemporaryRechargeOrderRequest) returns (H5RechargeOrderResponse);
  rpc ListTemporaryRechargeOrders(ListTemporaryRechargeOrdersRequest) returns (ListTemporaryRechargeOrdersResponse);
  rpc SubmitH5RechargeTx(SubmitH5RechargeTxRequest) returns (H5RechargeOrderResponse);
  rpc GetH5RechargeOrder(GetH5RechargeOrderRequest) returns (H5RechargeOrderResponse);
  rpc HandleMifapayNotify(HandleMifapayNotifyRequest) returns (HandleMifapayNotifyResponse);
  rpc HandleV5PayNotify(HandleV5PayNotifyRequest) returns (HandleV5PayNotifyResponse);
  rpc GetDiamondExchangeConfig(GetDiamondExchangeConfigRequest) returns (GetDiamondExchangeConfigResponse);
  rpc ListWalletTransactions(ListWalletTransactionsRequest) returns (ListWalletTransactionsResponse);
  rpc ListVipPackages(ListVipPackagesRequest) returns (ListVipPackagesResponse);
  rpc GetMyVip(GetMyVipRequest) returns (GetMyVipResponse);
  rpc PurchaseVip(PurchaseVipRequest) returns (PurchaseVipResponse);
  rpc DebitCPBreakupFee(DebitCPBreakupFeeRequest) returns (DebitCPBreakupFeeResponse);
  rpc DebitWheelDraw(DebitWheelDrawRequest) returns (DebitWheelDrawResponse);
  rpc GrantVip(GrantVipRequest) returns (GrantVipResponse);
  rpc ListAdminVipLevels(ListAdminVipLevelsRequest) returns (ListAdminVipLevelsResponse);
  rpc UpdateAdminVipLevels(UpdateAdminVipLevelsRequest) returns (UpdateAdminVipLevelsResponse);
  rpc CreditTaskReward(CreditTaskRewardRequest) returns (CreditTaskRewardResponse);
  rpc CreditLuckyGiftReward(CreditLuckyGiftRewardRequest) returns (CreditLuckyGiftRewardResponse);
  rpc CreditWheelReward(CreditWheelRewardRequest) returns (CreditWheelRewardResponse);
  rpc CreditRoomTurnoverReward(CreditRoomTurnoverRewardRequest) returns (CreditRoomTurnoverRewardResponse);
  rpc CreditInviteActivityReward(CreditInviteActivityRewardRequest) returns (CreditInviteActivityRewardResponse);
  rpc CreditAgencyOpeningReward(CreditAgencyOpeningRewardRequest) returns (CreditAgencyOpeningRewardResponse);
  rpc ApplyGameCoinChange(ApplyGameCoinChangeRequest) returns (ApplyGameCoinChangeResponse);
  rpc GetRedPacketConfig(GetRedPacketConfigRequest) returns (GetRedPacketConfigResponse);
  rpc UpdateRedPacketConfig(UpdateRedPacketConfigRequest) returns (UpdateRedPacketConfigResponse);
  rpc CreateRedPacket(CreateRedPacketRequest) returns (CreateRedPacketResponse);
  rpc ClaimRedPacket(ClaimRedPacketRequest) returns (ClaimRedPacketResponse);
  rpc ListRedPackets(ListRedPacketsRequest) returns (ListRedPacketsResponse);
  rpc GetRedPacket(GetRedPacketRequest) returns (GetRedPacketResponse);
  rpc ExpireRedPackets(ExpireRedPacketsRequest) returns (ExpireRedPacketsResponse);
  rpc RetryRedPacketRefund(RetryRedPacketRefundRequest) returns (RetryRedPacketRefundResponse);
}
