import { Router } from "express";
import {
  createAdminProductType,
  deleteAdminProductType,
  getAdminProductTypeById,
  listAdminProductTypes,
  updateAdminProductType,
} from "../controllers/productTypeController.js";
import { requireStaff } from "../middleware/authMiddleware.js";
import {
  validateBody,
  validateParams,
  validateQuery,
} from "../middleware/validateRequest.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import {
  createProductTypeSchema,
  productTypeIdParamSchema,
  productTypeListQuerySchema,
  updateProductTypeSchema,
} from "../validators/productTypeValidators.js";

const router = Router();

router.use(requireStaff);

router.get(
  "/",
  validateQuery(productTypeListQuerySchema),
  asyncHandler(listAdminProductTypes),
);

router.post(
  "/",
  validateBody(createProductTypeSchema),
  asyncHandler(createAdminProductType),
);

router.get(
  "/:id",
  validateParams(productTypeIdParamSchema),
  asyncHandler(getAdminProductTypeById),
);

router.patch(
  "/:id",
  validateParams(productTypeIdParamSchema),
  validateBody(updateProductTypeSchema),
  asyncHandler(updateAdminProductType),
);

router.delete(
  "/:id",
  validateParams(productTypeIdParamSchema),
  asyncHandler(deleteAdminProductType),
);

export default router;
