{
  "info": {
    "name": "ANTAI — Admin",
    "description": "Admin module to monitor & manage every vehicle linked to the ANTAI integration: visibility/binding status, archive state, unbinding reasons, exception handling, single + bulk visibility actions, and the disabled-company cascade.\n\nKey model: `vehicles.antai_status` (S/N/E) is the single source of truth, surfaced as BOTH 'ANTAI visibility' (S=Visible, N=Hidden, E=Exception) and 'binding status' (S=Bound, N=Unbound, E=Exception). Single enable/disable is synchronous; bulk + company cascade are queued on the 'antai' queue.\n\nGated by the vehicles permission (admin_vehicles.manage); superadmins bypass. Run 'Auth — Login' first to populate {{token}} (requires a superadministrator account). Base URL: https://api.fleet.dadycar.fr.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{token}}", "type": "string" }]
  },
  "variable": [
    { "key": "base_url", "value": "https://api.fleet.dadycar.fr" },
    { "key": "token", "value": "" },
    { "key": "vehicle_id", "value": "1" },
    { "key": "company_id", "value": "1" }
  ],
  "item": [
    {
      "name": "Auth",
      "item": [
        {
          "name": "Auth — Login (sets {{token}})",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "let json = pm.response.json();",
                  "let token = json.token || json.data?.token || json.access_token || json.data?.access_token;",
                  "if (token) { pm.collectionVariables.set('token', token); }"
                ]
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"email\": \"superadmin@dadycar.fr\",\n  \"password\": \"password\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/admin/auth/login",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "auth", "login"]
            }
          }
        }
      ]
    },
    {
      "name": "Vehicles",
      "description": "The ANTAI vehicle-management list and per-vehicle actions. The list runs withTrashed() so archived vehicles stay visible for audit/tracking.",
      "item": [
        {
          "name": "Stats",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "url": {
              "raw": "{{base_url}}/api/admin/antai/vehicles/stats",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "vehicles", "stats"]
            },
            "description": "Returns { total, visible, hidden, exceptions, open_exceptions, archived } (all counts include archived vehicles)."
          }
        },
        {
          "name": "Options (filter dropdowns)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "url": {
              "raw": "{{base_url}}/api/admin/antai/vehicles/options",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "vehicles", "options"]
            },
            "description": "Value/label option lists for every filter: companies, company_statuses, vehicle_statuses, antai_visibility (S/N/E), binding_statuses, archived, unbinding_reasons, exception_types, exception_resolutions, exception_statuses."
          }
        },
        {
          "name": "List (search + filters)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "url": {
              "raw": "{{base_url}}/api/admin/antai/vehicles?per_page=15",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "vehicles"],
              "query": [
                { "key": "per_page", "value": "15" },
                { "key": "search", "value": "", "description": "Company name, vehicle name, plate or VIN.", "disabled": true },
                { "key": "company_id", "value": "", "description": "companies.id of the owning company.", "disabled": true },
                { "key": "company_status", "value": "disabled", "description": "active | disabled (owning fleet account).", "disabled": true },
                { "key": "vehicle_status_id", "value": "", "description": "custom_status_id.", "disabled": true },
                { "key": "antai_visibility", "value": "exception", "description": "visible | hidden | exception (or S | N | E).", "disabled": true },
                { "key": "binding_status", "value": "unbound", "description": "bound | unbound | exception.", "disabled": true },
                { "key": "archived", "value": "archived", "description": "active | archived.", "disabled": true },
                { "key": "unbinding_reason", "value": "company_disabled", "description": "manual | company_disabled | external_removal | exception.", "disabled": true },
                { "key": "exception_type", "value": "already_linked_other_client", "description": "already_linked_other_client | removed_externally | sync_failure | antai_rejection | other.", "disabled": true },
                { "key": "exception_status", "value": "open", "description": "open | in_progress | resolved.", "disabled": true },
                { "key": "order_by", "value": "last_antai_updated_date", "description": "created_at | updated_at | last_antai_updated_date | numberplate | antai_status | antai_exception_status.", "disabled": true },
                { "key": "order", "value": "DESC", "description": "ASC | DESC.", "disabled": true }
              ]
            },
            "description": "Paginated list. Each row carries company, vehicle_name, numberplate, vin, vehicle_status, company_account_status, antai_visibility, binding_status, archive_status, unbinding_reason, exception block, and last_antai_updated_date."
          }
        },
        {
          "name": "Show (details)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "url": {
              "raw": "{{base_url}}/api/admin/antai/vehicles/{{vehicle_id}}",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "vehicles", "{{vehicle_id}}"]
            },
            "description": "Full detail view (includes archived vehicles)."
          }
        },
        {
          "name": "Enable visibility",
          "request": {
            "method": "POST",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "url": {
              "raw": "{{base_url}}/api/admin/antai/vehicles/{{vehicle_id}}/enable",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "vehicles", "{{vehicle_id}}", "enable"]
            },
            "description": "Adds the vehicle to ANTAI (antai_status → S). Synchronous. 200 on success with { vehicle, summary }; 422 if ineligible (invalid plate/model); 502 if ANTAI rejects or is unreachable (vehicle lands in exception state)."
          }
        },
        {
          "name": "Disable visibility",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"reason\": \"manual\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/admin/antai/vehicles/{{vehicle_id}}/disable",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "vehicles", "{{vehicle_id}}", "disable"]
            },
            "description": "Removes the vehicle from ANTAI (antai_status → N). Synchronous. Body: { reason } optional — one of manual | external_removal | company_disabled (defaults to manual). 502 if ANTAI removal fails (vehicle lands in exception state)."
          }
        },
        {
          "name": "Update exception (resolution tracking)",
          "request": {
            "method": "PATCH",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"status\": \"in_progress\",\n  \"exception_type\": \"already_linked_other_client\",\n  \"resolution\": \"external\",\n  \"detail\": \"Plate already bound to another client code at ANTAI; opened a ticket with ANTAI support.\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/admin/antai/vehicles/{{vehicle_id}}/exception",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "vehicles", "{{vehicle_id}}", "exception"]
            },
            "description": "Tracks exception resolution. Body: status (required: open | in_progress | resolved), exception_type (optional: already_linked_other_client | removed_externally | sync_failure | antai_rejection | other), resolution (optional: internal | external), detail (optional, max 2000). Does NOT change antai_status — enable/disable separately to set the real ANTAI state. status=resolved stamps resolved_at."
          }
        }
      ]
    },
    {
      "name": "Bulk actions",
      "description": "Select one or many vehicles and enable/disable visibility. Queued on the 'antai' queue and processed off-request — refresh the list to see results. The FE confirms before calling.",
      "item": [
        {
          "name": "Bulk enable",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"vehicle_ids\": [1, 2, 3]\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/admin/antai/vehicles/bulk/enable",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "vehicles", "bulk", "enable"]
            },
            "description": "Body: { vehicle_ids: [int] } (1–1000, must exist). Returns { queued }."
          }
        },
        {
          "name": "Bulk disable",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"vehicle_ids\": [1, 2, 3],\n  \"reason\": \"manual\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/api/admin/antai/vehicles/bulk/disable",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "vehicles", "bulk", "disable"]
            },
            "description": "Body: { vehicle_ids: [int], reason? } — reason one of manual | external_removal | company_disabled (defaults to manual). Returns { queued }."
          }
        }
      ]
    },
    {
      "name": "Disabled company handling",
      "description": "When a company account is disabled, all its vehicles must become unavailable in ANTAI. This runs automatically inside CompanyService::disableAccess; the endpoint below is the manual trigger of the same cascade. Records stay listed (unbinding_reason = company_disabled).",
      "item": [
        {
          "name": "Disable company vehicles (cascade)",
          "request": {
            "method": "POST",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "url": {
              "raw": "{{base_url}}/api/admin/antai/companies/{{company_id}}/disable-vehicles",
              "host": ["{{base_url}}"],
              "path": ["api", "admin", "antai", "companies", "{{company_id}}", "disable-vehicles"]
            },
            "description": "{{company_id}} = the company-role User id. Queues ANTAI removal for every non-hidden vehicle of the company (reason = company_disabled). Returns { queued }."
          }
        }
      ]
    }
  ]
}
