import type { FastifyInstance } from "fastify";
import { route } from "../../core/http/route.js";
import * as s from "./datahealth.service.js";

const H = "/api/projects/:projectId/monitor/holiday-attendance-audit", P = "/api/projects/:projectId", O = `${P}/ops`;
export async function datahealthRoutes(app: FastifyInstance): Promise<void> {
  route(app, "GET", "/projects/:p/datahealth/findings", { perm: "datahealth.view", v1: [`GET ${O}/data-quality`, `GET ${O}/risk-monitor`, `GET ${H}/scan`, `GET ${H}/records`, `GET ${P}/admin/phone-correction`, `GET ${P}/trainings/date-integrity/check`, "GET /api/projects/tp-mapping-diagnostics"] }, async (c) => s.findings(c));
  route(app, "GET", "/projects/:p/datahealth/summary", { perm: "datahealth.view" }, async (c) => s.summary(c));
  // V1's repair buttons are replaced by rules that stop the damage (real dates, one parent per row, holidays never counted) and by this check.
  route(app, "POST", "/projects/:p/datahealth/run", { perm: "datahealth.view", v1: [`POST ${O}/data-quality/repair-orphan-attendance`, `POST ${O}/data-quality/repair-scope-fields`, `DELETE ${H}/remove`, `POST ${P}/trainings/date-integrity/normalize`, "POST /api/projects/tp-mapping-diagnostics/repair", "POST /api/projects/tp-mapping-diagnostics/fix-membership-link"] }, async (c) => s.start(c));
}
