{
  "info": {
    "name": "Rapport LOM (FI-08) — Fleet",
    "description": "API for the **Rapport LOM** report (code FI-08) — the LOM verdissement declaration. Base URL points to dev2.dadycar.fr.\n\n**Setup**: set `{{token}}` to a valid auth.service bearer token (a company user with `view_reports`; `create_reports` for download/generate/schedule writes).\n\n**Key behaviours for the FE**:\n- The **Entreprise** filter is a real company (`company_id`) in the tenant's group (companies.parent_company_id) — options = the tenant company + its sub-companies; first option is `all` = \"Toutes les entreprises\".\n- Filters (from `/generate-config` → `data.fields`): only `company_id` (Entreprise) + `fiscal_year` (Année LOM).\n- `/preview` returns `{ header, graphs }` — `graphs` is the rows-of-cards: 3 KPIs, a `lom_trajectory` bar, and a `vehicle_synthesis` table (cols: Immatriculation · Énergie · CO₂ émission · Km · Date d'entrée au parc · VFE ?).\n- `/indicators`, `/use-cases`, `/similar` intentionally return empty for FI-08 (those sections are hidden).\n- **Download is synchronous**: `POST /download` builds the file inline and streams it back as an attachment (no polling). Handle the response as a **blob**. `format=csv` is the official data.gouv.fr declaration (etalab schema, one row). `pdf`/`xlsx` are human summaries.\n- **Scheduling** is multi-row per report (one per entreprise). Active/En pause = the `enabled` boolean. The recurring email delivery cron is not built yet (`next_run_at` stays null).",
    "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://dev2.dadycar.fr" },
    { "key": "token", "value": "" },
    { "key": "report_code", "value": "FI-08" },
    { "key": "schedule_id", "value": "" }
  ],
  "item": [
    {
      "name": "Report — read",
      "item": [
        {
          "name": "Header",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "Report card: title (\"Rapport LOM\"), description (no TAI), domain badge, audiences, and enabled formats (pdf, xlsx, csv).",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/header",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "header"]
            }
          }
        },
        {
          "name": "Generate config (filters)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "Filter schema for the Filtres & Génération card. `data.fields` = [ company_id (label \"Entreprise\", options = all + group companies), fiscal_year (\"Année LOM\") ].",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/generate-config",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "generate-config"]
            }
          }
        },
        {
          "name": "Preview (real data)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "On-page report: `data.header` + `data.graphs` (3 KPIs, lom_trajectory bar, vehicle_synthesis table). No TAI / Économie / data.gouv.fr cards.",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/preview",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "preview"]
            }
          }
        },
        {
          "name": "Preview (mock data)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "Same shape as the real preview but with illustrative demo values — useful for FE design before a tenant has data.",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/preview?mock_data=1",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "preview"],
              "query": [{ "key": "mock_data", "value": "1" }]
            }
          }
        },
        {
          "name": "Indicators (empty for LOM)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "Returns `{ items: [] }` for FI-08 — the \"Indicateurs mesurés\" section is hidden.",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/indicators",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "indicators"]
            }
          }
        },
        {
          "name": "Use cases (empty for LOM)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "Returns `{ items: [] }` for FI-08 — \"Cas d'usage recommandés\" is hidden.",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/use-cases",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "use-cases"]
            }
          }
        },
        {
          "name": "Similar (empty for LOM)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "Returns `[]` for FI-08 — \"Rapports similaires\" is hidden.",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/similar",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "similar"]
            }
          }
        },
        {
          "name": "Generations history",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "Async generation history (Historique des générations tab). Optional filters: format, status, user_id.",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/generations",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "generations"],
              "query": [
                { "key": "format", "value": "csv", "disabled": true },
                { "key": "status", "value": "done", "disabled": true },
                { "key": "user_id", "value": "", "disabled": true }
              ]
            }
          }
        }
      ]
    },
    {
      "name": "Generate & Download",
      "item": [
        {
          "name": "Download — CSV (data.gouv.fr declaration)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "description": "Synchronous: streams the official etalab verdissement CSV (one header + one aggregate row, 75 columns). Response is a file (Content-Disposition: attachment) — handle as a blob on the FE. `company_id` = \"all\" or a company id (the Entreprise scope).",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"format\": \"csv\",\n  \"fiscal_year\": \"2026\",\n  \"company_id\": \"all\"\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/download",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "download"]
            }
          }
        },
        {
          "name": "Download — PDF (one-page summary)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "description": "Synchronous: streams a one-page PDF summary (KPIs + trajectory + Synthèse extract). Handle as a blob.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"format\": \"pdf\",\n  \"fiscal_year\": \"2026\",\n  \"company_id\": \"all\"\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/download",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "download"]
            }
          }
        },
        {
          "name": "Download — XLSX (full per-vehicle list)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "description": "Synchronous: streams the XLSX (Résumé + full Synthèse + Déclaration sheets). Handle as a blob.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"format\": \"xlsx\",\n  \"fiscal_year\": \"2026\",\n  \"company_id\": \"all\"\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/download",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "download"]
            }
          }
        },
        {
          "name": "Generate (async — optional)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "description": "Legacy async path: queues a generation and returns the row to poll (status → done, then download_path). The Rapport LOM button should use the synchronous **Download** above instead; this stays for the Historique flow.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"format\": \"csv\",\n  \"fiscal_year\": \"2026\",\n  \"company_id\": \"all\"\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/generate",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "generate"]
            }
          }
        }
      ]
    },
    {
      "name": "Scheduling (Planification)",
      "item": [
        {
          "name": "List schedules",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "All schedules for this report (the \"Planifications existantes\" tab). Each item: id, name, enabled, status/status_label (Active|En pause), company {id,name} (= the entreprise/site), frequency {key,label}, period, format, time_of_day, recipients[], next_run_at, last_run_at.",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/schedules",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "schedules"]
            }
          }
        },
        {
          "name": "Schedule options (form selects)",
          "request": {
            "method": "GET",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "Select options for the schedule form: companies (entreprises = sites), frequencies, periods, formats.",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/schedules/options",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "schedules", "options"]
            }
          }
        },
        {
          "name": "Create schedule",
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "// Capture the new id into {{schedule_id}} for the update/delete requests.",
                  "try { var id = pm.response.json().data.id; if (id) pm.collectionVariables.set('schedule_id', id); } catch (e) {}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "request": {
            "method": "POST",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "description": "Create a schedule (one per entreprise). `frequency_key` required; `company_id` is the entreprise scope (omit/null = all). `enabled` true = Active. Returns the created item (id auto-saved to {{schedule_id}}).",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"name\": \"Déclaration LOM — ACME\",\n  \"frequency_key\": \"yearly\",\n  \"format\": \"csv\",\n  \"period\": \"this_year\",\n  \"company_id\": null,\n  \"enabled\": true,\n  \"recipients\": [\"fiscalite@acme.fr\"]\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/schedules",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "schedules"]
            }
          }
        },
        {
          "name": "Update schedule (e.g. pause)",
          "request": {
            "method": "PUT",
            "header": [
              { "key": "Accept", "value": "application/json" },
              { "key": "Content-Type", "value": "application/json" }
            ],
            "description": "Partial update (PUT semantics: only sent keys change). Example body pauses the schedule.",
            "body": {
              "mode": "raw",
              "raw": "{\n  \"enabled\": false\n}",
              "options": { "raw": { "language": "json" } }
            },
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/schedules/{{schedule_id}}",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "schedules", "{{schedule_id}}"]
            }
          }
        },
        {
          "name": "Delete schedule",
          "request": {
            "method": "DELETE",
            "header": [{ "key": "Accept", "value": "application/json" }],
            "description": "Remove a schedule by id.",
            "url": {
              "raw": "{{base_url}}/api/v1/fleet/reports/{{report_code}}/schedules/{{schedule_id}}",
              "host": ["{{base_url}}"],
              "path": ["api", "v1", "fleet", "reports", "{{report_code}}", "schedules", "{{schedule_id}}"]
            }
          }
        }
      ]
    }
  ]
}
