{
  "info": {
    "name": "Walaay Public API v1",
    "description": "Merchant POS API — use wl_test_ keys for sandbox. Idempotency-Key is required on writes.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "baseUrl", "value": "http://localhost:3000/api/v1" },
    { "key": "apiKey", "value": "wl_test_REPLACE.REPLACE" },
    { "key": "idempotencyKey", "value": "" }
  ],
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{apiKey}}", "type": "string" }]
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "if (!pm.collectionVariables.get('idempotencyKey')) {",
          "  pm.collectionVariables.set('idempotencyKey', require('uuid').v4 ? require('uuid').v4() : Date.now().toString(36) + Math.random().toString(36).slice(2));",
          "}"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "Health",
      "request": {
        "auth": { "type": "noauth" },
        "method": "GET",
        "url": "{{baseUrl}}/health"
      }
    },
    {
      "name": "Me",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/me"
      }
    },
    {
      "name": "Lookup customer",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/customers/lookup?phone=%2B966501234567"
      }
    },
    {
      "name": "Create customer",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Idempotency-Key", "value": "{{idempotencyKey}}-cust" },
          { "key": "Content-Type", "value": "application/json" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"phone\": \"+966501234567\",\n  \"display_name\": \"Sara\",\n  \"consent\": true\n}"
        },
        "url": "{{baseUrl}}/customers"
      }
    },
    {
      "name": "Earn points",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Idempotency-Key", "value": "{{idempotencyKey}}-earn" },
          { "key": "Content-Type", "value": "application/json" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"customer\": { \"phone\": \"+966501234567\" },\n  \"order\": { \"reference\": \"INV-DEMO-1\", \"total_halalas\": 11500 },\n  \"points\": 100\n}"
        },
        "url": "{{baseUrl}}/transactions/earn"
      }
    },
    {
      "name": "List rewards",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/rewards"
      }
    },
    {
      "name": "List branches",
      "request": {
        "method": "GET",
        "url": "{{baseUrl}}/branches"
      }
    }
  ]
}
