{
  "info": {
    "_postman_id": "d6c9c4f4-35e9-4d6b-a2c3-72f0c7d1c5a2",
    "name": "Yemen Address - Beneficiary API",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "Auth",
      "item": [
        {
          "name": "Register (Email) -> stores token",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Stores token in collection variables', function () {",
                  "  var json = pm.response.json();",
                  "  if (json && json.token) {",
                  "    pm.collectionVariables.set('token', json.token);",
                  "  }",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"{{name}}\",\n  \"email\": \"{{email}}\",\n  \"mobile\": \"{{mobile}}\",\n  \"password\": \"{{password}}\",\n  \"device_name\": \"postman\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/beneficiary/register/email",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "register",
                "email"
              ]
            }
          }
        },
        {
          "name": "Register (Mobile) -> stores token",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Stores token in collection variables', function () {",
                  "  var json = pm.response.json();",
                  "  if (json && json.token) {",
                  "    pm.collectionVariables.set('token', json.token);",
                  "  }",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"{{name}}\",\n  \"mobile\": \"{{mobile}}\",\n  \"password\": \"{{password}}\",\n  \"device_name\": \"postman\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/beneficiary/register/mobile",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "register",
                "mobile"
              ]
            }
          }
        },
        {
          "name": "Login (mobile or email)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Stores token in collection variables', function () {",
                  "  var json = pm.response.json();",
                  "  if (json && json.token) {",
                  "    pm.collectionVariables.set('token', json.token);",
                  "  }",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"login\": \"{{login}}\",\n  \"password\": \"{{password}}\",\n  \"device_name\": \"postman\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/beneficiary/login",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "login"
              ]
            }
          }
        },
        {
          "name": "Me",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{token}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "url": {
              "raw": "{{base_url}}/api/beneficiary/me",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "me"
              ]
            }
          }
        },
        {
          "name": "Logout (revoke current token)",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{token}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "url": {
              "raw": "{{base_url}}/api/beneficiary/logout",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "logout"
              ]
            }
          }
        }
      ]
    },
    {
      "name": "Addresses",
      "item": [
        {
          "name": "Search Buildings (stores first result)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Stores first building result', function () {",
                  "  var json = pm.response.json();",
                  "  var first = json && json.data && json.data.length ? json.data[0] : null;",
                  "  if (first) {",
                  "    if (first.building_code) pm.collectionVariables.set('buildingCode', first.building_code);",
                  "  }",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{token}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "url": {
              "raw": "{{base_url}}/api/beneficiary/addresses-search?q={{search}}&limit={{limit}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "addresses-search"
              ],
              "query": [
                {
                  "key": "q",
                  "value": "{{search}}"
                },
                {
                  "key": "limit",
                  "value": "{{limit}}"
                }
              ]
            }
          }
        },
        {
          "name": "Add Address (by building_code) -> stores beneficiaryAddressId",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('Stores beneficiaryAddressId', function () {",
                  "  var json = pm.response.json();",
                  "  if (json && json.data && json.data.id) {",
                  "    pm.collectionVariables.set('beneficiaryAddressId', json.data.id);",
                  "    if (json.data.code) {",
                  "      pm.collectionVariables.set('beneficiaryAddressCode', json.data.code);",
                  "    }",
                  "  }",
                  "});"
                ]
              }
            }
          ],
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{token}}",
                  "type": "string"
                }
              ]
            },
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"building_code\": \"{{buildingCode}}\",\n  \"unit_label\": \"{{unitLabel}}\",\n  \"floor_label\": \"{{floorLabel}}\",\n  \"details\": \"{{details}}\",\n  \"label\": \"Home\",\n  \"is_primary\": true\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/beneficiary/addresses",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "addresses"
              ]
            }
          }
        },
        {
          "name": "List My Addresses",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{token}}",
                  "type": "string"
                }
              ]
            },
            "method": "GET",
            "url": {
              "raw": "{{base_url}}/api/beneficiary/addresses?q={{search}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "addresses"
              ],
              "query": [
                {
                  "key": "q",
                  "value": "{{search}}"
                }
              ]
            }
          }
        },
        {
          "name": "Update My Address (label / is_primary)",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{token}}",
                  "type": "string"
                }
              ]
            },
            "method": "PATCH",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"label\": \"Updated label\",\n  \"unit_label\": \"{{unitLabel}}\",\n  \"floor_label\": \"{{floorLabel}}\",\n  \"details\": \"{{details}}\",\n  \"is_primary\": true\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/beneficiary/addresses/{{beneficiaryAddressId}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "addresses",
                "{{beneficiaryAddressId}}"
              ]
            }
          }
        },
        {
          "name": "Delete My Address",
          "request": {
            "auth": {
              "type": "bearer",
              "bearer": [
                {
                  "key": "token",
                  "value": "{{token}}",
                  "type": "string"
                }
              ]
            },
            "method": "DELETE",
            "url": {
              "raw": "{{base_url}}/api/beneficiary/addresses/{{beneficiaryAddressId}}",
              "host": [
                "{{base_url}}"
              ],
              "path": [
                "api",
                "beneficiary",
                "addresses",
                "{{beneficiaryAddressId}}"
              ]
            }
          }
        }
      ]
    }
  ],
  "variable": [
    {
      "key": "base_url",
      "value": "http://localhost:8000"
    },
    {
      "key": "login",
      "value": ""
    },
    {
      "key": "name",
      "value": ""
    },
    {
      "key": "email",
      "value": ""
    },
    {
      "key": "mobile",
      "value": ""
    },
    {
      "key": "password",
      "value": ""
    },
    {
      "key": "token",
      "value": ""
    },
    {
      "key": "search",
      "value": ""
    },
    {
      "key": "limit",
      "value": "20"
    },
    {
      "key": "beneficiaryAddressId",
      "value": "1"
    },
    {
      "key": "buildingCode",
      "value": ""
    },
    {
      "key": "beneficiaryAddressCode",
      "value": ""
    },
    {
      "key": "unitLabel",
      "value": ""
    },
    {
      "key": "floorLabel",
      "value": ""
    },
    {
      "key": "details",
      "value": ""
    }
  ]
}
