/**
 * `GET /api/v1/birds` — tonight's nocturnal migration, and, far more often, the
 * reason there is none.
 *
 * No query, for the same reason `/radar` takes none: one granule covers the
 * whole state and every board is a rectangle inside it.
 *
 * The body is publicly cacheable and carries nothing personal at all — BirdCast
 * is a Cornell Lab forecast product aggregated to counties, and the county
 * coordinates are Census internal points. The interesting property is the other
 * one: **an empty body is the normal body**, so this route answers 200 with an
 * empty `counties` array and a filled-in `quiet` for about fourteen hours of
 * every twenty-four. A client that treats an empty array as a fault will be
 * wrong most of the day, which is why `quiet` is not optional on the wire.
 */

import type { FastifyInstance } from "fastify";
import { publicCache } from "../cache.ts";
import type { BirdsService } from "../birds/index.ts";

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