syntax = "proto3";

package hyapp.game.v1;

option go_package = "hyapp.local/api/proto/game/v1;gamev1";

// RequestMeta 是 game-service 内部 RPC 的最小追踪和租户上下文。
message RequestMeta {
  string request_id = 1;
  string caller = 2;
  string gateway_node_id = 3;
  int64 actor_user_id = 4;
  int64 sent_at_ms = 5;
  string app_code = 6;
}

message GamePlatform {
  string app_code = 1;
  string platform_code = 2;
  string platform_name = 3;
  string status = 4;
  string api_base_url = 5;
  int32 sort_order = 6;
  int64 created_at_ms = 7;
  int64 updated_at_ms = 8;
}

message GameCatalogItem {
  string app_code = 1;
  string game_id = 2;
  string platform_code = 3;
  string provider_game_id = 4;
  string game_name = 5;
  string category = 6;
  string icon_url = 7;
  string cover_url = 8;
  string launch_mode = 9;
  string orientation = 10;
  int64 min_coin = 11;
  string status = 12;
  int32 sort_order = 13;
  repeated string tags = 14;
  int64 created_at_ms = 15;
  int64 updated_at_ms = 16;
}

message AppGame {
  string game_id = 1;
  string platform_code = 2;
  string name_key = 3;
  string name = 4;
  string icon_url = 5;
  string cover_url = 6;
  string category = 7;
  string launch_mode = 8;
  string orientation = 9;
  int64 min_coin = 10;
  bool enabled = 11;
  bool maintenance = 12;
  int32 sort_order = 13;
}

message ListGamesRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string scene = 3;
  string room_id = 4;
  int64 region_id = 5;
  string language = 6;
  string client_platform = 7;
}

message ListGamesResponse {
  repeated AppGame games = 1;
  int64 server_time_ms = 2;
}

message LaunchGameRequest {
  RequestMeta meta = 1;
  int64 user_id = 2;
  string display_user_id = 3;
  string game_id = 4;
  string scene = 5;
  string room_id = 6;
}

message LaunchGameResponse {
  string session_id = 1;
  string launch_url = 2;
  int64 expires_at_ms = 3;
  string orientation = 4;
  int64 server_time_ms = 5;
}

message CallbackRequest {
  RequestMeta meta = 1;
  string platform_code = 2;
  string operation = 3;
  bytes raw_body = 4;
  map<string, string> headers = 5;
  map<string, string> query = 6;
  string remote_addr = 7;
}

message CallbackResponse {
  bytes raw_body = 1;
  string content_type = 2;
}

message ListPlatformsRequest {
  RequestMeta meta = 1;
  string status = 2;
}

message ListPlatformsResponse {
  repeated GamePlatform platforms = 1;
  int64 server_time_ms = 2;
}

message UpsertPlatformRequest {
  RequestMeta meta = 1;
  GamePlatform platform = 2;
}

message PlatformResponse {
  GamePlatform platform = 1;
  int64 server_time_ms = 2;
}

message ListCatalogRequest {
  RequestMeta meta = 1;
  string platform_code = 2;
  string status = 3;
  int32 page_size = 4;
  string cursor = 5;
}

message ListCatalogResponse {
  repeated GameCatalogItem games = 1;
  string next_cursor = 2;
  int64 server_time_ms = 3;
}

message UpsertCatalogRequest {
  RequestMeta meta = 1;
  GameCatalogItem game = 2;
}

message CatalogResponse {
  GameCatalogItem game = 1;
  int64 server_time_ms = 2;
}

message SetGameStatusRequest {
  RequestMeta meta = 1;
  string game_id = 2;
  string status = 3;
}

service GameAppService {
  rpc ListGames(ListGamesRequest) returns (ListGamesResponse);
  rpc LaunchGame(LaunchGameRequest) returns (LaunchGameResponse);
}

service GameCallbackService {
  rpc HandleCallback(CallbackRequest) returns (CallbackResponse);
}

service GameAdminService {
  rpc ListPlatforms(ListPlatformsRequest) returns (ListPlatformsResponse);
  rpc UpsertPlatform(UpsertPlatformRequest) returns (PlatformResponse);
  rpc ListCatalog(ListCatalogRequest) returns (ListCatalogResponse);
  rpc UpsertCatalog(UpsertCatalogRequest) returns (CatalogResponse);
  rpc SetGameStatus(SetGameStatusRequest) returns (CatalogResponse);
}
