/**
 * `GET /api/v1/radar` — the statewide reflectivity lattice, for everybody.
 *
 * No query, for the reason `/fires` and `/satellites` take none: the answer does
 * not vary by who asked or where they are looking. There is one composite over
 * California, the boards are rectangles inside it, and with no parameter there
 * is no key space and none of the amplification concerns that shape
 * `regions.ts`.
 *
 * ### Publicly cacheable, and the reason is structural
 *
 * The upstream store carries `echo_cells.distance_km`, measured from a private
 * house. It cannot reach a shared cache, and not because this route is careful:
 * because **this box has no database**. cloud-1 serves a projection with a
 * hand-written column list and there is nothing here to be careless with. What a
 * CDN can hold is a grid of NWS reflectivity — a public-domain US government
 * product, the same one every weather site in the country redraws.
 *
 * `publicCache` still applies its own credential check, so a request that
 * arrived with a session attached falls back to the fail-closed
 * `private, no-store` default.
 */

import type { FastifyInstance } from "fastify";
import { publicCache } from "../cache.ts";
import type { RadarService } from "../radar/index.ts";

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