import express from "express";
import {
  cancelOrderController,
  createOrderRD,
  getAllOrdersByDistributor,
  getCancelledOrders,
  getDeliveredInvoicesForPd,
  getDispatchedInvoicesForPd,
  getInvoiceDetailsByIdForPD,
  getNewOrders,
  getPendignOrders,
  getPlacedOrderById,
  getPlacedOrdersForPD,
  getPlacedOrdersForRD,
  getProcessingInvoicesForPd,
  getSinglePlacedOrderForPD,
  getSinglePlacedOrderForRD,
  gettotalorderandvalueofrd,
  processOrder,
  updateCourierStatusToDeliveredForPD,
  updateCourierStatusToDispatchedForPD,
} from "./rdOrderController.js";
import { isAuthenticatedRD } from "../../middlewares/rdAuth.js";

import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
const router = express.Router();

router.route("/rd-place-order").post(isAuthenticatedRD, createOrderRD);
router.route("/rd-place-order").get(isAuthenticatedRD, getPlacedOrdersForRD);
router
  .route("/rd-place-order/:id")
  .get(isAuthenticatedRD, getSinglePlacedOrderForRD);
// routes for the Admin
router
  .route("/get-single-placed-order-rd/:id")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getPlacedOrderById);
router
  .route("/single-rd-order/:distributorId")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getAllOrdersByDistributor);
// routes for the PD
router
  .route("/pd-get-all-place-order")
  .get(isAuthenticatedUser, getPlacedOrdersForPD);

router
  .route("/pd-get-single-place-order/:id")
  .get(isAuthenticatedUser, getSinglePlacedOrderForPD);

router.route("/pd-process-order").post(isAuthenticatedUser, processOrder);
router.route("/pd-get-new-orders").get(isAuthenticatedUser, getNewOrders);
router
  .route("/pd-get-pending-orders")
  .get(isAuthenticatedUser, getPendignOrders);
router
  .route("/pd-get-cancelled-orders")
  .get(isAuthenticatedUser, getCancelledOrders);

router
  .route("/pd-get-processing-invoices")
  .get(isAuthenticatedUser, getProcessingInvoicesForPd);
router
  .route("/pd-get-dispatched-invoices")
  .get(isAuthenticatedUser, getDispatchedInvoicesForPd);
router
  .route("/pd-get-delivered-invoices")
  .get(isAuthenticatedUser, getDeliveredInvoicesForPd);
router
  .route("/pd-get-invoices/:invoiceId")
  .get(isAuthenticatedUser, getInvoiceDetailsByIdForPD);
router
  .route("/pd-cancel-order/:id")
  .put(isAuthenticatedUser, cancelOrderController);
router.route("/pd-invoice/dispatched/:invoiceId").put(
  isAuthenticatedUser,

  updateCourierStatusToDispatchedForPD
);

router.route("/pd-invoice/delivered/:invoiceId").put(
  isAuthenticatedUser,

  updateCourierStatusToDeliveredForPD
);
router
  .route("/single-rd-ordercount/:distributorId")
  .get(isAuthenticatedUser, authorizeRoles("admin"), gettotalorderandvalueofrd);
export default router;
