/**
 * `GET /api/v1/fires` — every active wildfire this box knows about, for
 * everybody, everywhere.
 *
 * The second route here that takes no query at all, and for the same reason
 * `/satellites` takes none: the answer does not vary by who asked or where they
 * are looking. The whole state's live incident set is small, the boards are
 * rectangles inside it, and the clip is a client-side operation
 * (`promote()` in `src/server/fires.ts`) that has to happen anyway. With no
 * parameter there is no key space, so none of the amplification concerns that
 * shape `regions.ts` apply.
 *
 * ### Publicly cacheable, and this is the one that needed thinking about
 *
 * Every other publicly-cached route here carries data about the sky. This one
 * carries data derived from a database centred on somebody's house — so the
 * question is not "is a fire location personal data" (it is not; CAL FIRE
 * publishes every one of these on its own website) but "could a shared cache
 * hold something it should not". It cannot, and the reason is structural rather
 * than a review: the four home-relative columns are never in the body, because
 * the machine that holds them serves a projection and this box has no database
 * to be careless with. What a CDN can keep is a list of public agency records.
 *
 * `publicCache` still applies its own credential check — a request that arrived
 * with a session attached falls back to the fail-closed `private, no-store`
 * default — so nothing changes for a signed-in viewer either.
 */

import type { FastifyInstance } from "fastify";
import { publicCache } from "../cache.ts";
import type { Services } from "../services.ts";

export function registerFires(app: FastifyInstance, services: Services): void {
  app.get("/api/v1/fires", async (req, reply) => {
    const body = await services.fires.current();
    publicCache(req, reply, body.ttlSeconds);
    return body;
  });
}
