import { wrapAsyncHandler } from "@batch-cooking/express-tools";
import { Router } from "express";
import { requireAdmin } from "../../middlewares/require-admin.js";
import { getMonitoring } from "./admin-monitoring.service.js";

/** Router mounted at `/admin/monitoring` (via `admin.routes.ts`) — behind {@link requireAdmin}. */
export const adminMonitoringRouter = Router();

/**
 * Actively probes Postgres, the API, `tech-step-intent-service` and the LLM
 * worker's heartbeat, returning a {@link MonitoringView} status board (see
 * {@link getMonitoring}). No params; the admin UI polls it on an interval.
 */
adminMonitoringRouter.get(
  "/",
  requireAdmin,
  wrapAsyncHandler(async (_req, res) => {
    res.status(200).json(await getMonitoring());
  }),
);
