{
  "info": {
    "_postman_id": "2dd91e00-8f0a-4a4a-b966-1adad8ea4f26",
    "name": "RMS - Image Upload Test Flow",
    "description": "Tests auth -> image upload -> create menu item with uploaded image URL.\n\nNote: Current RMS uses image_url pattern. If your upload endpoint is not implemented yet, use the fallback request with an external URL.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "1) Login (Get Bearer Token)",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"email\": \"{{email}}\",\n  \"password\": \"{{password}}\"\n}"
        },
        "url": {
          "raw": "{{base_url}}/api/v1/auth/login",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "auth",
            "login"
          ]
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('Login status is 200', function () {",
              "  pm.response.to.have.status(200);",
              "});",
              "",
              "var json = {};",
              "try { json = pm.response.json(); } catch (e) {}",
              "",
              "var token = json.token || (json.data && (json.data.token || json.data.access_token));",
              "if (token) {",
              "  pm.collectionVariables.set('bearer_token', token);",
              "}",
              "",
              "var branchId = json.active_branch_id || (json.user && (json.user.active_branch_id || json.user.branch_id)) || (json.data && json.data.user && json.data.user.branch_id);",
              "if (branchId) {",
              "  pm.collectionVariables.set('branch_id', String(branchId));",
              "}",
              "",
              "pm.test('Bearer token saved', function () {",
              "  pm.expect(pm.collectionVariables.get('bearer_token')).to.be.a('string').and.not.empty;",
              "});"
            ]
          }
        }
      ]
    },
    {
      "name": "2) Upload Image (Multipart)",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "key": "Authorization",
            "value": "Bearer {{bearer_token}}"
          }
        ],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "image",
              "type": "file",
              "src": ""
            },
            {
              "key": "folder",
              "value": "menu-items",
              "type": "text"
            }
          ]
        },
        "url": {
          "raw": "{{base_url}}/api/v1/uploads/image",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "uploads",
            "image"
          ]
        },
        "description": "If your project does not have this endpoint yet, this request may return 404. In that case, use request #4 (external URL fallback)."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('Upload request executed', function () {",
              "  pm.expect(pm.response.code).to.be.oneOf([200, 201, 400, 401, 404, 422]);",
              "});",
              "",
              "if (pm.response.code === 200 || pm.response.code === 201) {",
              "  var json = {};",
              "  try { json = pm.response.json(); } catch (e) {}",
              "",
              "  var uploaded =",
              "    json.image_url ||",
              "    json.url ||",
              "    (json.data && (json.data.image_url || json.data.url || json.data.path));",
              "",
              "  if (uploaded) {",
              "    pm.collectionVariables.set('uploaded_image_url', uploaded);",
              "  }",
              "",
              "  pm.test('Uploaded image URL captured', function () {",
              "    pm.expect(pm.collectionVariables.get('uploaded_image_url')).to.be.a('string').and.not.empty;",
              "  });",
              "}"
            ]
          }
        }
      ]
    },
    {
      "name": "3) Create Menu Item (Using Uploaded URL)",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "key": "Authorization",
            "value": "Bearer {{bearer_token}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"category_id\": {{category_id}},\n  \"name\": \"Postman Test Item\",\n  \"description\": \"Item created from Postman upload flow\",\n  \"price\": 12.5,\n  \"image_url\": \"{{uploaded_image_url}}\",\n  \"is_vegetarian\": false,\n  \"is_vegan\": false,\n  \"is_spicy\": false,\n  \"preparation_time\": 15,\n  \"status\": \"active\"\n}"
        },
        "url": {
          "raw": "{{base_url}}/api/v1/menu-items",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "menu-items"
          ]
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('Menu item create status', function () {",
              "  pm.expect(pm.response.code).to.be.oneOf([200, 201, 401, 403, 404, 422]);",
              "});"
            ]
          }
        }
      ]
    },
    {
      "name": "4) Fallback: Create Menu Item (External image_url)",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "key": "Authorization",
            "value": "Bearer {{bearer_token}}"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"category_id\": {{category_id}},\n  \"name\": \"Postman URL Item\",\n  \"description\": \"Fallback test with direct URL\",\n  \"price\": 11.0,\n  \"image_url\": \"https://images.unsplash.com/photo-1540189549336-e6e99c3679fe\",\n  \"is_vegetarian\": true,\n  \"is_vegan\": false,\n  \"is_spicy\": true,\n  \"preparation_time\": 12,\n  \"status\": \"active\"\n}"
        },
        "url": {
          "raw": "{{base_url}}/api/v1/menu-items",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "api",
            "v1",
            "menu-items"
          ]
        },
        "description": "Use this request if upload endpoint is not implemented and you just want to test current URL-based image pattern."
      }
    }
  ],
  "variable": [
    {
      "key": "base_url",
      "value": "http://127.0.0.1:8000"
    },
    {
      "key": "email",
      "value": "admin@example.com"
    },
    {
      "key": "password",
      "value": "password123"
    },
    {
      "key": "category_id",
      "value": "1"
    },
    {
      "key": "bearer_token",
      "value": ""
    },
    {
      "key": "uploaded_image_url",
      "value": ""
    },
    {
      "key": "branch_id",
      "value": ""
    }
  ]
}
