{
  "info": {
    "name": "AI Budget Middleware (Local)",
    "description": "ERP-facing API for the local AI Budget Middleware.\n\nVariables:\n- base_url: where `php artisan serve` is running (default http://127.0.0.1:8000)\n- api_key: the ERP_API_KEY value from your .env\n- request_id: auto-filled after a successful upload\n\nUsage:\n1. Run `php artisan serve` and `php artisan queue:work`.\n2. Send \"1. Upload Word File\" (pick a .docx under Body > form-data > file).\n3. Send \"2. Get Result\" to fetch the processed result.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "http://127.0.0.1:8000",
      "type": "string"
    },
    {
      "key": "api_key",
      "value": "change-me-to-a-long-random-secret",
      "type": "string"
    },
    {
      "key": "request_id",
      "value": "1",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "1. Upload Word File",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Save request_id from the response so request 2 can use it.",
              "if (pm.response.code === 202) {",
              "    const json = pm.response.json();",
              "    if (json.request_id) {",
              "        pm.collectionVariables.set('request_id', json.request_id);",
              "        console.log('Saved request_id =', json.request_id);",
              "    }",
              "}",
              "pm.test('Upload accepted (202)', function () {",
              "    pm.expect(pm.response.code).to.eql(202);",
              "});"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "X-API-KEY",
            "value": "{{api_key}}"
          },
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "file",
              "type": "file",
              "description": "Pick a .docx (or .doc) budget file here.",
              "src": []
            }
          ]
        },
        "url": {
          "raw": "{{base_url}}/api/documents",
          "host": ["{{base_url}}"],
          "path": ["api", "documents"]
        },
        "description": "Uploads a Word budget file. Returns 202 with a request_id and queues processing."
      }
    },
    {
      "name": "2. Get Result",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-API-KEY",
            "value": "{{api_key}}"
          },
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/api/documents/{{request_id}}",
          "host": ["{{base_url}}"],
          "path": ["api", "documents", "{{request_id}}"]
        },
        "description": "Fetches the processing result (status, extracted_text, extracted_tables_json, ai_response, error_message) for the last uploaded request_id."
      }
    }
  ]
}
