import { Router } from "express";
import { getOrderForAdmin, listOrdersForAdmin, updateOrderForAdmin } from "../controllers/orderController.js";
import { requireStaff } from "../middleware/authMiddleware.js";
import { validateBody, validateParams, validateQuery } from "../middleware/validateRequest.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import { adminOrderListQuerySchema, orderIdParamSchema, updateOrderSchema } from "../validators/orderValidators.js";

const router = Router();

router.use(requireStaff);

router.get("/", validateQuery(adminOrderListQuerySchema), asyncHandler(listOrdersForAdmin));
router.get("/:id", validateParams(orderIdParamSchema), asyncHandler(getOrderForAdmin));
router.patch("/:id", validateParams(orderIdParamSchema), validateBody(updateOrderSchema), asyncHandler(updateOrderForAdmin));

export default router;
