import {
  createExportRequestHandler,
  downloadExportRequestFileHandler,
  listExportRequestsHandler,
  reviewExportRequestHandler,
} from "@/controllers/admin/export-requests/export-requests.controller";
import { withConsoleUserSession } from "@/middlewares/withConsoleUserSession";
import { Hono } from "hono";

export const ExportRequestsRoutes = new Hono();

/*
 * Gated on a console session only, with the finer rules applied in the handlers:
 *
 *  - submitting is open to any signed-in user (the console already decides which
 *    export buttons they see, per-section, via their role privileges)
 *  - listing returns the whole queue to a super admin and only the caller's own
 *    requests to everyone else
 *  - approving/rejecting is super-admin only
 *  - downloading the workbook is super-admin for any request, and the requester's
 *    own only once approved
 *
 * There is no per-feature privilege for "export approvals", so `withConsoleUserRole`
 * has nothing meaningful to check here.
 */
ExportRequestsRoutes.post("/", withConsoleUserSession(), createExportRequestHandler);
ExportRequestsRoutes.get("/", withConsoleUserSession(), listExportRequestsHandler);
ExportRequestsRoutes.get(
  "/:id/file",
  withConsoleUserSession(),
  downloadExportRequestFileHandler,
);
ExportRequestsRoutes.post(
  "/:id/review",
  withConsoleUserSession(),
  reviewExportRequestHandler,
);
