import { Router } from "express";
import { createOrder, getMyOrderById, listMyOrders } from "../controllers/orderController.js";
import { uploadPrescription } from "../controllers/uploadController.js";
import { requireAuth } from "../middleware/authMiddleware.js";
import { prescriptionUpload } from "../middleware/uploadMiddleware.js";
import { validateBody, validateParams, validateQuery } from "../middleware/validateRequest.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import { createOrderSchema, customerOrderListQuerySchema, orderIdParamSchema } from "../validators/orderValidators.js";

const router = Router();

router.use(requireAuth);

router.get("/", validateQuery(customerOrderListQuerySchema), asyncHandler(listMyOrders));
router.post("/", validateBody(createOrderSchema), asyncHandler(createOrder));
router.get("/:id", validateParams(orderIdParamSchema), asyncHandler(getMyOrderById));
router.post(
  "/upload-prescription",
  prescriptionUpload.array("file", 1),
  asyncHandler(uploadPrescription),
);

export default router;
