import express from "express";
import rateLimit from "express-rate-limit";
import { Auth } from "$controllers/index.js";

import { jwt } from "$middlewares/index.js";

const router = express.Router();

const otpSendLimiter = rateLimit({
  windowMs: 15 * 60 * 1000,
  max: 5,
  standardHeaders: true,
  legacyHeaders: false,
  message: {
    message:
      "تعداد درخواست‌های ورود بیش از حد مجاز است، کمی بعد دوباره تلاش کنید",
  },
});

const otpVerifyLimiter = rateLimit({
  windowMs: 15 * 60 * 1000,
  max: 10,
  standardHeaders: true,
  legacyHeaders: false,
  message: {
    message:
      "تعداد تلاش‌های تایید بیش از حد مجاز است، کمی بعد دوباره تلاش کنید",
  },
});

router.get("/captcha", Auth.GET_CAPTCHA);
router.post("/otp/send", otpSendLimiter, Auth.SEND_OTP);
router.post("/otp/verify", otpVerifyLimiter, Auth.VERIFY_OTP);
router.post("/sync/otp/send", jwt, Auth.SYNC_SEND_OTP);
router.post("/sync/otp/verify", jwt, Auth.SYNC_VERIFY_OTP);
router.get("/me", jwt, Auth.ME);
router.post("/impersonate/consume", Auth.CONSUME_IMPERSONATION_LINK);
router.post("/impersonate/:userId", jwt, Auth.IMPERSONATE_USER);
router.post("/logout", jwt, Auth.LOGOUT);

export default router;
