const express =
  require("express");

const {
  exportSubmissionPdf,
  exportSubmissionPdfBatch,
  exportSubmissionsExcel
} = require(
  "../controllers/adminSubmissionExportController"
);

const {
  getSubmissions,
  getReviewers,
  assignSubmission
} = require(
  "../controllers/adminSubmissionController"
);

const {
  getSubmissionDetail,
  startSubmissionReview,
  approveSubmission,
  returnSubmission,
  rejectSubmission,
  downloadSubmissionDocument
} = require(
  "../controllers/adminSubmissionReviewController"
);

const {
  verifyAdminToken
} = require(
  "../middleware/adminAuth"
);

const {
  authorizeAdminRoles
} = require(
  "../middleware/adminAuthorization"
);

const router =
  express.Router();

router.use(
  verifyAdminToken
);

/* =========================================================
   LISTS
   ========================================================= */

router.get(
  "/",
  getSubmissions
);

router.get(
  "/reviewers",
  getReviewers
);


/* =========================================================
   STAFF RECORD EXPORTS

   Bulk routes must remain before /:submissionId.
   ========================================================= */

router.get(
  "/export/excel",
  exportSubmissionsExcel
);

router.post(
  "/export/pdf-batch",
  exportSubmissionPdfBatch
);

router.get(
  "/:submissionId/export/pdf",
  exportSubmissionPdf
);

/* =========================================================
   SUBMISSION DETAIL
   ========================================================= */

router.get(
  "/:submissionId",
  getSubmissionDetail
);

router.get(
  "/:submissionId/documents/:documentId/download",
  downloadSubmissionDocument
);

/* =========================================================
   REVIEW ACTIONS
   ========================================================= */

router.patch(
  "/:submissionId/assign",
  authorizeAdminRoles(
    "super_admin",
    "hr_admin"
  ),
  assignSubmission
);

router.patch(
  "/:submissionId/start-review",
  authorizeAdminRoles(
    "super_admin",
    "hr_admin",
    "hr_reviewer"
  ),
  startSubmissionReview
);

router.patch(
  "/:submissionId/approve",
  authorizeAdminRoles(
    "super_admin",
    "hr_admin",
    "hr_reviewer"
  ),
  approveSubmission
);

router.patch(
  "/:submissionId/return",
  authorizeAdminRoles(
    "super_admin",
    "hr_admin",
    "hr_reviewer"
  ),
  returnSubmission
);

router.patch(
  "/:submissionId/reject",
  authorizeAdminRoles(
    "super_admin",
    "hr_admin",
    "hr_reviewer"
  ),
  rejectSubmission
);

module.exports = router;