import { param, query } from "express-validator";
import { Router } from "express";

import { notificationsController } from "../controllers/notificationsController.js";
import { handleValidation } from "../middleware/validation.js";
import { asyncHandler } from "../utils/asyncHandler.js";

const router = Router();

router.get(
  "/",
  [
    query("limit").optional().isInt({ min: 1, max: 100 }).withMessage("La limite est invalide."),
    query("unread_only")
      .optional()
      .isIn(["true", "false", "1", "0", "oui", "non", "yes", "no"])
      .withMessage("Le filtre unread_only est invalide."),
    handleValidation,
  ],
  asyncHandler(notificationsController.list),
);
router.put(
  "/:id/read",
  [
    param("id").isInt({ min: 1 }).withMessage("Identifiant de notification invalide."),
    handleValidation,
  ],
  asyncHandler(notificationsController.markRead),
);
router.put("/read-all", asyncHandler(notificationsController.markAllRead));
router.delete(
  "/:id",
  [
    param("id").isInt({ min: 1 }).withMessage("Identifiant de notification invalide."),
    handleValidation,
  ],
  asyncHandler(notificationsController.remove),
);

export default router;
