import { Router } from "express";
import {
  getPublicProductBySlug,
  getPublicProductFilters,
  listPublicProducts,
} from "../controllers/productController.js";
import {
  validateParams,
  validateQuery,
} from "../middleware/validateRequest.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import {
  productListQuerySchema,
  productSlugParamSchema,
} from "../validators/productValidators.js";

const router = Router();

router.get(
  "/",
  validateQuery(productListQuerySchema),
  asyncHandler(listPublicProducts),
);
router.get("/filters", asyncHandler(getPublicProductFilters));
router.get(
  "/:slug",
  validateParams(productSlugParamSchema),
  asyncHandler(getPublicProductBySlug),
);

export default router;
