/** 代码示例（语言无关，三语共用） */
export const SSO_JWT_PAYLOAD_EXAMPLE = `{
  "site_code": "demo",
  "site_player_id": "100001",
  "iat": 1718000000,
  "exp": 1718000300
}`;

export const SSO_JWT_SIGN_EXAMPLE = `const header = base64url(JSON.stringify({ alg: "HS256", typ: "JWT" }));
const payload = base64url(JSON.stringify({
  site_code: "demo",
  site_player_id: "100001",
  iat: Math.floor(Date.now() / 1000),
  exp: Math.floor(Date.now() / 1000) + 300,
}));
const sig = hmacSha256Base64url(\`\${header}.\${payload}\`, SSO_JWT_SECRET);
const token = \`\${header}.\${payload}.\${sig}\`;`;

export const SSO_ENTRY_URL = `https://{lottery_host}/?token={JWT}`;

export const SSO_POSTMESSAGE = `iframe.contentWindow.postMessage(
  { type: "MAIN_INIT_TOKEN", token: jwt, source: "main-site" },
  "https://lottery.example.com"
);`;

export const PLAYER_ME_REQUEST = `GET /api/v1/player/me
Authorization: Bearer {JWT}
Accept-Language: zh`;

export const PLAYER_ME_SUCCESS = `{
  "code": 0,
  "msg": "success",
  "data": {
    "id": 42,
    "site_code": "demo",
    "site_player_id": "100001",
    "auth_source": "main_site_sso",
    "funding_mode": "wallet",
    "username": null,
    "nickname": null,
    "default_currency": "NPR",
    "status": 0,
    "locale": "zh",
    "last_login_at": "2026-06-14T10:00:00+00:00",
    "created_at": "2026-06-14T10:00:00+00:00"
  }
}`;

export const IFRAME_CHILD_READY = `{
  "type": "LOTTERY_READY",
  "payload": { "url": "https://lottery.example.com/", "userAgent": "..." },
  "timestamp": 1718000000000,
  "source": "lottery-iframe"
}`;

export const IFRAME_PARENT_INIT = `{
  "type": "MAIN_INIT_TOKEN",
  "token": "eyJhbGciOiJIUzI1NiIs...",
  "timestamp": 1718000000000,
  "source": "main-site"
}`;

export const ACCEPTANCE_PLAYER_ME = `curl -sS "https://{lottery_api}/api/v1/player/me" \\
  -H "Authorization: Bearer {JWT}" \\
  -H "Accept: application/json"`;

export const ACCEPTANCE_WALLET_DEBIT = `curl -sS -X POST "https://{wallet_host}/wallet/debit-for-lottery" \\
  -H "Authorization: Bearer {wallet_api_key}" \\
  -H "Content-Type: application/json" \\
  -d '{
    "site_code": "demo",
    "site_player_id": "100001",
    "player_id": 42,
    "currency_code": "NPR",
    "amount_minor": 100,
    "idempotent_key": "accept-debit-001"
  }'`;

export const PLAYER_AUTH_ERROR = `HTTP/1.1 401 Unauthorized

{
  "code": 8002,
  "msg": "Token 无效或已过期",
  "data": null
}`;

export const WALLET_BALANCE_RESPONSE = `{
  "success": true,
  "data": { "main_balance": 500000, "currency_code": "NPR" }
}`;

export const WALLET_DEBIT_REQUEST = `POST /wallet/debit-for-lottery
Authorization: Bearer {wallet_api_key}

{
  "site_code": "demo",
  "site_player_id": "100001",
  "player_id": 42,
  "currency_code": "NPR",
  "amount_minor": 2000,
  "idempotent_key": "TI-20260610-abc"
}`;

export const WALLET_SUCCESS = `{
  "success": true,
  "external_ref_no": "MW-001",
  "data": { "main_balance": 498000, "currency_code": "NPR" }
}`;

export const WALLET_FAIL = `{
  "success": false,
  "message": "main balance insufficient",
  "data": { "main_balance": 500, "currency_code": "NPR" }
}`;

export const WALLET_CREDIT_REQUEST = `POST /wallet/credit-from-lottery
Authorization: Bearer {wallet_api_key}

{
  "site_code": "demo",
  "site_player_id": "100001",
  "player_id": 42,
  "currency_code": "NPR",
  "amount_minor": 2000,
  "idempotent_key": "TO-20260610-abc"
}`;

export const TRANSFER_IN = `POST /api/v1/wallet/transfer-in
Authorization: Bearer {player_jwt}

{ "amount": 2000, "currency": "NPR", "idempotent_key": "ti-001" }`;

export const TRANSFER_OUT = `POST /api/v1/wallet/transfer-out
Authorization: Bearer {player_jwt}

{ "amount": 1000, "currency": "NPR", "idempotent_key": "to-001" }`;

export const TRANSFER_SUCCESS = `{
  "code": 0,
  "msg": "success",
  "data": {
    "transfer_no": "TI20260614001",
    "direction": "in",
    "currency_code": "NPR",
    "amount": 2000,
    "status": "success",
    "external_ref_no": "debit-for-lottery-1718360000-a1b2c3",
    "balance": 2000,
    "log_id": "WX_20260614_0001",
    "lottery_balance_after": 2000,
    "lottery_available_after": 2000,
    "finished_at": "2026-06-14T10:00:00+00:00"
  }
}`;
