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

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

const router = Router();

router.get(
  "/",
  [
    query("q")
      .optional()
      .isString()
      .isLength({ max: 120 })
      .withMessage("La recherche est invalide."),
    query("limit").optional().isInt({ min: 1, max: 20 }).withMessage("La limite est invalide."),
    handleValidation,
  ],
  asyncHandler(searchController.search),
);

export default router;
