import { Router } from "express";
import {
  archiveAdminProduct,
  createAdminProduct,
  getAdminProductById,
  listAdminProducts,
  updateAdminProduct,
} from "../controllers/productController.js";
import { requireStaff } from "../middleware/authMiddleware.js";
import { validateBody, validateParams, validateQuery } from "../middleware/validateRequest.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import {
  createProductSchema,
  productIdParamSchema,
  productListQuerySchema,
  updateProductSchema,
} from "../validators/productValidators.js";

const router = Router();

router.use(requireStaff);

router.get("/", validateQuery(productListQuerySchema), asyncHandler(listAdminProducts));
router.post("/", validateBody(createProductSchema), asyncHandler(createAdminProduct));
router.get("/:id", validateParams(productIdParamSchema), asyncHandler(getAdminProductById));
router.patch("/:id", validateParams(productIdParamSchema), validateBody(updateProductSchema), asyncHandler(updateAdminProduct));
router.delete("/:id", validateParams(productIdParamSchema), asyncHandler(archiveAdminProduct));

export default router;
