const router = require("express").Router();
const { authenticateAdmin, audit } = require("../../middleware");
const { authLimiter, passwordResetLimiter, verificationLimiter } = require('../../middleware/rateLimiter');
const { rules, body, validate } = require("../../middleware/validation")
const AdminAuthController = require("../../controllers/admin/adminAuthController");

router.post("/login", AdminAuthController.login);
router.post(
  '/verify-2fa',
  authLimiter,
  [
    rules.email,
    body('code').isInt().isLength({ min: 6, max: 6 }),
  ],
  validate,
  AdminAuthController.verify2fa
);
router.post(
  '/resend-2fa',
  verificationLimiter,
  [rules.email],
  validate,
  AdminAuthController.resendVerification
);
router.get("/me", authenticateAdmin, AdminAuthController.me);
router.post(
    '/register',
    authLimiter,
    [
        rules.email,
        rules.password,
        rules.confirm_password,
        body('name').trim().isString().isLength({ max: 50 }),
        body('role').optional()
    ],
    validate,
    AdminAuthController.register
);

router.post(
    '/refresh-token',
    [body('refreshToken').notEmpty().withMessage('Refresh token is required')],
    validate,
    AdminAuthController.refreshToken
);

module.exports = router