syntax = "proto3";

package freeexile.shop;

// Supported Client Operating Platforms
enum PlatformType {
  PLATFORM_UNKNOWN = 0;
  PLATFORM_IOS = 1;                  // Apple App Store (Strict StoreKit 2 compliance)
  PLATFORM_ANDROID_PLAYSTORE = 2;   // Google Play Store (Strict Play Billing compliance)
  PLATFORM_ANDROID_SIDELOAD = 3;    // Official APK sideload (Direct card/crypto permitted)
  PLATFORM_WEB_PC = 4;              // Official Web Top-Up Portal & PC client
  PLATFORM_MACOS_DIRECT = 5;        // Direct Mac build (outside Mac App Store)
}

// Allowed Payment Gateways
enum PaymentGateway {
  GATEWAY_UNKNOWN = 0;
  GATEWAY_APPLE_IAP = 1;            // Apple In-App Purchase (StoreKit 2)
  GATEWAY_GOOGLE_PLAY = 2;          // Google Play In-App Billing
  GATEWAY_STRIPE = 3;               // Stripe Credit Card / Apple Pay on Web
  GATEWAY_PAYPAL = 4;               // PayPal Global
  GATEWAY_CRYPTO_WEB3 = 5;          // Web3 Non-Custodial Crypto Wallet (EVM / Solana)
  GATEWAY_LOCAL_VIETNAM = 6;        // MoMo / VNPay / Bank QR (Direct portal only)
}

// Product Categories in MegaShop
enum ShopCategory {
  CAT_UNKNOWN = 0;
  CAT_COINS = 1;                    // Hard Currency: Huyết Cổ Tệ (Outcast Blood Coins)
  CAT_SKINS = 2;                    // Cosmetical weapon effects, martial robes, mount auras
  CAT_ITEMS = 3;                    // Convenience, teleport charms, storage expanders
  CAT_CHESTS = 4;                   // Mystery Boxes / Gacha with public transparent drop rates
  CAT_PASSES = 5;                   // Monthly Subscriptions / Thần Ma Lệnh (Battle Pass)
}

// Web3 Supported Blockchains
enum CryptoChain {
  CHAIN_UNKNOWN = 0;
  CHAIN_ETHEREUM = 1;
  CHAIN_ARBITRUM = 2;
  CHAIN_POLYGON = 3;
  CHAIN_SOLANA = 4;
  CHAIN_BNB_CHAIN = 5;
}

// Web3 Supported Currencies
enum CryptoToken {
  TOKEN_UNKNOWN = 0;
  TOKEN_USDT = 1;                   // Tether USD Stablecoin (ERC20 / SPL)
  TOKEN_USDC = 2;                   // Circle USD Coin (ERC20 / SPL)
  TOKEN_ETH = 3;                    // Native Ether
  TOKEN_SOL = 4;                    // Native Solana
}

// Individual Loot Box Probability Specification
message ChestDropItemProbability {
  string item_id = 1;
  string item_name_key = 2;
  uint32 rarity = 3;                // 0=Common, 1=Magic, 2=Rare, 3=Unique/Legendary
  float drop_chance_percent = 4;    // e.g. 0.05 for 0.05%
  bool is_guaranteed_pity = 5;      // Part of pity counter system
}

// MegaShop Product Item
message ShopProduct {
  string product_id = 1;            // Global SKU, e.g. "coin_pack_100", "skin_azure_dragon"
  string name_i18n_key = 2;
  string description_i18n_key = 3;
  ShopCategory category = 4;
  uint32 coin_price = 5;            // Price in In-Game Gold Cores (0 if direct fiat purchase)
  float base_fiat_usd = 6;          // Direct purchase price in USD (0 if purchased with coins)
  uint32 original_coin_price = 7;   // For discount display
  uint32 discount_percent = 8;      // 0 to 100
  uint32 purchase_limit_per_account = 9; // 0 = unlimited
  uint64 available_until_ts = 10;   // 0 = permanent
  string badge_label = 11;          // e.g. "HOT", "NEW", "LIMITED", "SALE"
  repeated ChestDropItemProbability chest_drop_rates = 12; // Required for CAT_CHESTS
}

// Catalog Query
message GetCatalogRequest {
  string account_id = 1;
  ShopCategory category = 2;
  PlatformType platform = 3;
  string country_code = 4;          // ISO 3166-1 alpha-2 (e.g., "VN", "US", "JP")
  string locale = 5;
}

message GetCatalogResponse {
  repeated ShopProduct products = 1;
  uint64 catalog_version = 2;
  string user_country_code = 3;
}

// Payment Methods Query (Subject to platform policy compliance)
message GetPaymentMethodsRequest {
  string account_id = 1;
  PlatformType platform = 2;
  string country_code = 3;
  string client_version = 4;
}

message PaymentMethodOption {
  PaymentGateway gateway = 1;
  string display_name = 2;
  string icon_url = 3;
  bool is_recommended = 4;
  float bonus_coin_multiplier = 5;  // e.g. 1.10 for +10% bonus coins on direct portal
}

message GetPaymentMethodsResponse {
  repeated PaymentMethodOption allowed_gateways = 1;
  PlatformType resolved_platform = 2;
  string compliance_notice = 3;     // e.g. "Apple App Store Guideline 3.1.1 compliant"
}

// Order Creation
message CreatePaymentOrderRequest {
  string account_id = 1;
  string product_id = 2;
  PlatformType platform = 3;
  PaymentGateway gateway = 4;
  string country_code = 5;
  // Optional Web3 specific params
  CryptoChain crypto_chain = 6;
  CryptoToken crypto_token = 7;
  string buyer_wallet_address = 8;
}

message Web3OrderDetails {
  string merchant_vault_address = 1;
  string required_amount_atomic = 2; // In Wei or Lamports
  float required_amount_human = 3;   // e.g. 19.99 USDT
  string token_contract_address = 4;
  uint32 chain_id = 5;
  uint64 nonce = 6;
  uint64 expires_at_ts = 7;
  string eip712_domain_json = 8;
}

message CreatePaymentOrderResponse {
  string order_id = 1;
  bool success = 2;
  string error_message = 3;
  float amount_fiat = 4;
  string currency_code = 5;         // USD, VND, EUR, JPY
  Web3OrderDetails web3_details = 6; // Populated only if GATEWAY_CRYPTO_WEB3
  string gateway_client_token = 7;  // Apple StoreKit ProductID / Stripe Client Secret
}

// Receipt & Transaction Verification
message VerifyPaymentReceiptRequest {
  string account_id = 1;
  string order_id = 2;
  PaymentGateway gateway = 3;
  string receipt_payload = 4;       // StoreKit 2 JWS token / Google Purchase Token / tx_hash
  string tx_hash = 5;               // Specifically for Web3 Crypto
  uint64 chain_id = 6;
}

message VerifyPaymentReceiptResponse {
  string order_id = 1;
  bool verified = 2;
  string error_message = 3;
  string product_id = 4;
  uint32 delivered_coins = 5;
  repeated string delivered_item_uuids = 6;
  uint64 processed_timestamp = 7;
}
