import { wrapAsyncHandler } from "@batch-cooking/express-tools";
import { Router } from "express";
import {
  getAllergies,
  getDiets,
  getIngredients,
  getSources,
  getTechSteps,
  getUnits,
  getUtensils,
} from "./reference.service.js";

/**
 * Router mounted at `/reference` in app.ts. Every route is deliberately
 * public (no `requireAuth`) — this is static reference data, not
 * per-household state, and the signup wizard (household/regime/allergen
 * steps) needs to read it before an account — and therefore a session —
 * exists. `/ingredients` follows the same reasoning even though it's only
 * consumed post-login (the recipe catalog) — it's still non-administrable
 * reference data, no reason to require a session to read it.
 */
export const referenceRouter = Router();

referenceRouter.get(
  "/diets",
  wrapAsyncHandler(async (_req, res) => {
    res.status(200).json(await getDiets());
  }),
);

referenceRouter.get(
  "/allergies",
  wrapAsyncHandler(async (_req, res) => {
    res.status(200).json(await getAllergies());
  }),
);

referenceRouter.get(
  "/ingredients",
  wrapAsyncHandler(async (_req, res) => {
    res.status(200).json(await getIngredients());
  }),
);

referenceRouter.get(
  "/units",
  wrapAsyncHandler(async (_req, res) => {
    res.status(200).json(await getUnits());
  }),
);

referenceRouter.get(
  "/tech-steps",
  wrapAsyncHandler(async (_req, res) => {
    res.status(200).json(await getTechSteps());
  }),
);

referenceRouter.get(
  "/utensils",
  wrapAsyncHandler(async (_req, res) => {
    res.status(200).json(await getUtensils());
  }),
);

referenceRouter.get(
  "/sources",
  wrapAsyncHandler(async (_req, res) => {
    res.status(200).json(await getSources());
  }),
);
