const express = require("express");

const {
  rateLimit
} = require(
  "express-rate-limit"
);

const {
  getCurrentCampaign,
  validateGhanaCard,
  identifyStaff,
  getSubmissionSession
} = require(
  "../controllers/publicPortalController"
);

const {
  verifyGhanaCardToken,
  verifySubmissionToken
} = require(
  "../middleware/publicPortalAuth"
);

const router =
  express.Router();

const ghanaCardLimiter =
  rateLimit({
    windowMs:
      15 * 60 * 1000,

    limit:
      10,

    standardHeaders:
      "draft-8",

    legacyHeaders:
      false,

    message: {
      success: false,
      message:
        "Too many Ghana Card verification attempts. Please wait and try again."
    }
  });

const staffIdLimiter =
  rateLimit({
    windowMs:
      15 * 60 * 1000,

    limit:
      10,

    standardHeaders:
      "draft-8",

    legacyHeaders:
      false,

    message: {
      success: false,
      message:
        "Too many Staff ID verification attempts. Please wait and try again."
    }
  });

router.get(
  "/campaign",
  getCurrentCampaign
);

router.post(
  "/validate-ghana-card",
  ghanaCardLimiter,
  validateGhanaCard
);

router.post(
  "/identify",
  staffIdLimiter,
  verifyGhanaCardToken,
  identifyStaff
);

router.get(
  "/submission/session",
  verifySubmissionToken,
  getSubmissionSession
);

module.exports = router;