{
  "info": {
    "name": "PM-WANI XML API (v1)",
    "description": "PM-WANI spec-compliant XML endpoints. All requests/responses are XML. Base URL is configurable via {{base_url}}.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "base_url", "value": "https://flutter.pmwani.net/api/wani/v1" },
    { "key": "mobile", "value": "9999999999" },
    { "key": "auth_token", "value": "" },
    { "key": "session_token", "value": "" }
  ],
  "item": [
    {
      "name": "0. Ping (health check)",
      "request": {
        "method": "GET",
        "header": [{ "key": "Accept", "value": "application/xml" }],
        "url": { "raw": "{{base_url}}/ping", "host": ["{{base_url}}"], "path": ["ping"] }
      }
    },
    {
      "name": "1. Registry — List PDOAs",
      "request": {
        "method": "GET",
        "header": [{ "key": "Accept", "value": "application/xml" }],
        "url": { "raw": "{{base_url}}/registry/pdoa-list", "host": ["{{base_url}}"], "path": ["registry", "pdoa-list"] }
      }
    },
    {
      "name": "2. Hotspots — Nearby (Nagpur)",
      "request": {
        "method": "GET",
        "header": [{ "key": "Accept", "value": "application/xml" }],
        "url": {
          "raw": "{{base_url}}/hotspots?lat=21.1458&lng=79.0882&radius=5",
          "host": ["{{base_url}}"],
          "path": ["hotspots"],
          "query": [
            { "key": "lat", "value": "21.1458" },
            { "key": "lng", "value": "79.0882" },
            { "key": "radius", "value": "5" }
          ]
        }
      }
    },
    {
      "name": "3. Auth — Initiate",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "const xml = pm.response.text();",
              "const match = xml.match(/<Token>([^<]+)<\\/Token>/);",
              "if (match) {",
              "    pm.collectionVariables.set('auth_token', match[1]);",
              "    console.log('Saved auth_token:', match[1]);",
              "}"
            ],
            "type": "text/javascript"
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/xml" },
          { "key": "Accept", "value": "application/xml" }
        ],
        "body": {
          "mode": "raw",
          "raw": "<?xml version=\"1.0\"?>\n<AuthRequest>\n  <User><Mobile>{{mobile}}</Mobile></User>\n  <Hotspot>\n    <SSID>PM-WANI</SSID>\n    <BSSID>00:11:22:33:44:55</BSSID>\n  </Hotspot>\n</AuthRequest>"
        },
        "url": { "raw": "{{base_url}}/auth/initiate", "host": ["{{base_url}}"], "path": ["auth", "initiate"] }
      }
    },
    {
      "name": "4. Auth — Validate (creates session)",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "const xml = pm.response.text();",
              "const match = xml.match(/<SessionToken>([^<]+)<\\/SessionToken>/);",
              "if (match) {",
              "    pm.collectionVariables.set('session_token', match[1]);",
              "    console.log('Saved session_token:', match[1]);",
              "}"
            ],
            "type": "text/javascript"
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/xml" },
          { "key": "Accept", "value": "application/xml" }
        ],
        "body": {
          "mode": "raw",
          "raw": "<?xml version=\"1.0\"?>\n<TokenValidation>\n  <Token>{{auth_token}}</Token>\n</TokenValidation>"
        },
        "url": { "raw": "{{base_url}}/auth/validate", "host": ["{{base_url}}"], "path": ["auth", "validate"] }
      }
    },
    {
      "name": "5. Session — Status",
      "request": {
        "method": "GET",
        "header": [{ "key": "Accept", "value": "application/xml" }],
        "url": {
          "raw": "{{base_url}}/session/status?token={{session_token}}",
          "host": ["{{base_url}}"],
          "path": ["session", "status"],
          "query": [{ "key": "token", "value": "{{session_token}}" }]
        }
      }
    },
    {
      "name": "6. Session — End",
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/xml" },
          { "key": "Accept", "value": "application/xml" }
        ],
        "body": {
          "mode": "raw",
          "raw": "<?xml version=\"1.0\"?>\n<SessionEnd>\n  <Token>{{session_token}}</Token>\n  <DataUsedBytes>1048576000</DataUsedBytes>\n</SessionEnd>"
        },
        "url": { "raw": "{{base_url}}/session/end", "host": ["{{base_url}}"], "path": ["session", "end"] }
      }
    },
    {
      "name": "Error Cases",
      "item": [
        {
          "name": "404 — Invalid route",
          "request": {
            "method": "GET",
            "url": { "raw": "{{base_url}}/does-not-exist", "host": ["{{base_url}}"], "path": ["does-not-exist"] }
          }
        },
        {
          "name": "400 — Missing lat/lng",
          "request": {
            "method": "GET",
            "url": { "raw": "{{base_url}}/hotspots", "host": ["{{base_url}}"], "path": ["hotspots"] }
          }
        },
        {
          "name": "404 — Unknown user",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/xml" }],
            "body": {
              "mode": "raw",
              "raw": "<?xml version=\"1.0\"?>\n<AuthRequest>\n  <User><Mobile>0000000000</Mobile></User>\n  <Hotspot><SSID>PM-WANI</SSID></Hotspot>\n</AuthRequest>"
            },
            "url": { "raw": "{{base_url}}/auth/initiate", "host": ["{{base_url}}"], "path": ["auth", "initiate"] }
          }
        },
        {
          "name": "401 — Invalid token",
          "request": {
            "method": "POST",
            "header": [{ "key": "Content-Type", "value": "application/xml" }],
            "body": {
              "mode": "raw",
              "raw": "<?xml version=\"1.0\"?>\n<TokenValidation>\n  <Token>fake-token-xyz</Token>\n</TokenValidation>"
            },
            "url": { "raw": "{{base_url}}/auth/validate", "host": ["{{base_url}}"], "path": ["auth", "validate"] }
          }
        }
      ]
    }
  ]
}
