import express from "express";
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
import {
  createOrder,
  getCancelledOrdersAdmin,
  getDeliveredOrdersAdmin,
  getDispatchedOrdersAdmin,
  getOrderCounts,
  getPlacedNewOrderAdmin,
  getPlacedOrder,
  getPlacedOrderById,
  getProcessingOrdersAdmin,
  processOrder,
  cancelOrderController,
  getPlacedPendingOrderAdmin,
  getProcessingInvoices,
  updateCourierStatusToDispatched,
  getInvoiceDetailsById,
  getDeliveredInvoices,
  getDispatchedInvoices,
  updateCourierStatusToDelivered,
  getAllOrdersByDistributor,
  gettotalorderandvalueofpd,
} from "./pdOrderController.js";

const router = express.Router();

router
  .route("/order-place")
  .post(
    isAuthenticatedUser,
    authorizeRoles("principal-Distributor"),
    createOrder
  );
// Define the route for processing an order
router
  .route("/processing-order")
  .post(isAuthenticatedUser, authorizeRoles("admin"), processOrder);
// Define the route for cancel an order
router
  .route("/cancel-order/:id")
  .put(isAuthenticatedUser, authorizeRoles("admin"), cancelOrderController);
router
  .route("/get-placed-order-pd")
  .get(
    isAuthenticatedUser,
    authorizeRoles("principal-Distributor"),
    getPlacedOrder
  );
router
  .route("/get-single-placed-order-pd/:id")
  .get(isAuthenticatedUser, getPlacedOrderById);
router
  .route("/get-new-order-admin")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getPlacedNewOrderAdmin);
router
  .route("/get-pending-order-admin")
  .get(
    isAuthenticatedUser,
    authorizeRoles("admin"),
    getPlacedPendingOrderAdmin
  );
router
  .route("/get-cancelled-order-admin")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getCancelledOrdersAdmin);
router
  .route("/get-dispatched-order-admin")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getDispatchedOrdersAdmin);
router
  .route("/get-processing-order-admin")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getProcessingOrdersAdmin);
router
  .route("/get-delivered-order-admin")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getDeliveredOrdersAdmin);
router
  .route("/get-processing-invoice-admin")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getProcessingInvoices);
router
  .route("/get-dispatched-invoice-admin")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getDispatchedInvoices);
router
  .route("/get-delivered-invoice-admin")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getDeliveredInvoices);
router
  .route("/invoice/details/:invoiceId")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getInvoiceDetailsById);
router
  .route("/invoice/dispatched/:invoiceId")
  .put(
    isAuthenticatedUser,
    authorizeRoles("admin"),
    updateCourierStatusToDispatched
  );
router
  .route("/invoice/delivered/:invoiceId")
  .put(
    isAuthenticatedUser,
    authorizeRoles("admin"),
    updateCourierStatusToDelivered
  );
router
  .route("/single-pd-order/:distributorId")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getAllOrdersByDistributor);
  router
  .route("/single-pd-ordercount/:distributorId")
  .get(isAuthenticatedUser, authorizeRoles("admin"), gettotalorderandvalueofpd);
router.route("/get-counts-pdOrders").get(isAuthenticatedUser, getOrderCounts);

export default router;
