{
  "info": {
    "name": "Flight Crew Management API",
    "description": "Complete API collection for Flight Crew Management System",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "1. LOGIN (Get JWT Token)",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "if (pm.response.code === 200) {",
              "    try {",
              "        let jsonData = pm.response.json();",
              "        pm.environment.set('jwt_token', jsonData.token);",
              "        console.log('✅ JWT Token saved: ' + jsonData.token.substring(0, 20) + '...');",
              "    } catch (e) {",
              "        console.log('❌ Error parsing token: ' + e);",
              "    }",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"email\": \"pilot@example.com\",\n  \"password\": \"password123\"\n}"
        },
        "url": {
          "raw": "{{base_url}}/auth/login.php",
          "host": ["{{base_url}}"],
          "path": ["auth", "login.php"]
        }
      }
    },
    {
      "name": "2. SEARCH Crew",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "pm.test('Status code is 200', function () {",
              "    pm.response.to.have.status(200);",
              "});",
              "",
              "pm.test('Response has results', function () {",
              "    let jsonData = pm.response.json();",
              "    pm.expect(jsonData.results).to.be.an('array');",
              "});"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{jwt_token}}"
          }
        ],
        "url": {
          "raw": "{{base_url}}/flight/crews/search.php?q=ali&crew_role=cabin_crew&limit=15",
          "host": ["{{base_url}}"],
          "path": ["flight", "crews", "search.php"],
          "query": [
            {
              "key": "q",
              "value": "ali"
            },
            {
              "key": "crew_role",
              "value": "cabin_crew"
            },
            {
              "key": "limit",
              "value": "15"
            }
          ]
        }
      }
    },
    {
      "name": "3. LIST Crew (by Flight)",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "pm.test('Status code is 200', function () {",
              "    pm.response.to.have.status(200);",
              "});",
              "",
              "pm.test('Response has crew data', function () {",
              "    let jsonData = pm.response.json();",
              "    pm.expect(jsonData.data).to.be.an('object');",
              "});"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{jwt_token}}"
          }
        ],
        "url": {
          "raw": "{{base_url}}/flight/crews/list.php?flight_id=1",
          "host": ["{{base_url}}"],
          "path": ["flight", "crews", "list.php"],
          "query": [
            {
              "key": "flight_id",
              "value": "1"
            }
          ]
        }
      }
    },
    {
      "name": "4. GET Available Crew",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "pm.test('Status code is 200', function () {",
              "    pm.response.to.have.status(200);",
              "});"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{jwt_token}}"
          }
        ],
        "url": {
          "raw": "{{base_url}}/flight/crews/available.php?crew_role=pilot",
          "host": ["{{base_url}}"],
          "path": ["flight", "crews", "available.php"],
          "query": [
            {
              "key": "crew_role",
              "value": "pilot"
            }
          ]
        }
      }
    },
    {
      "name": "5. ASSIGN Crew (POST)",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{jwt_token}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"flight_id\": 1,\n  \"user_id\": 2,\n  \"crew_role\": \"pilot\",\n  \"notes\": \"Assigned as backup captain\"\n}"
        },
        "url": {
          "raw": "{{base_url}}/flight/crews/assign.php",
          "host": ["{{base_url}}"],
          "path": ["flight", "crews", "assign.php"]
        }
      }
    },
    {
      "name": "6. UPDATE Crew Notes (PUT)",
      "request": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{jwt_token}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"flight_crew_id\": 1,\n  \"notes\": \"Updated notes for this crew member\"\n}"
        },
        "url": {
          "raw": "{{base_url}}/flight/crews/notes.php",
          "host": ["{{base_url}}"],
          "path": ["flight", "crews", "notes.php"]
        }
      }
    },
    {
      "name": "7. REMOVE Crew (DELETE)",
      "request": {
        "method": "DELETE",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{jwt_token}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"flight_crew_id\": 1,\n  \"reason\": \"No longer needed\"\n}"
        },
        "url": {
          "raw": "{{base_url}}/flight/crews/remove.php",
          "host": ["{{base_url}}"],
          "path": ["flight", "crews", "remove.php"]
        }
      }
    },
    {
      "name": "8. GET User's Assigned Flights",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{jwt_token}}"
          }
        ],
        "url": {
          "raw": "{{base_url}}/user/assigned-flights.php",
          "host": ["{{base_url}}"],
          "path": ["user", "assigned-flights.php"]
        }
      }
    }
  ],
  "variable": [
    {
      "key": "base_url",
      "value": "http://localhost/slipstream",
      "type": "string"
    },
    {
      "key": "jwt_token",
      "value": "",
      "type": "string"
    }
  ]
}
