




const express = require("express");

const router = express.Router();

const dispatchController = require("../../controllers/dispatch/dispatchController");

const authenticate = require("../../middlewares/authenticate");


/**
 * @swagger
 * tags:
 *   name: Dispatch
 *   description: Dispatch management APIs
 */


// ======================================================
// DISPATCH DASHBOARD ROUTES
// ======================================================


// GET DISPATCH DASHBOARD PRODUCTS
router.get(
  "/dashboard-products",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get dispatch dashboard products'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getDispatchDashboardProducts
);


// ======================================================
// ALLOCATION ROUTES
// ======================================================


// GET ALL PRODUCT ALLOCATIONS
router.get(
  "/allocations",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get all product dispatch allocations'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getProductDispatchAllocations
);


// GET PRODUCT WISE ALLOCATIONS
router.get(
  "/allocations/:productId",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get dispatch allocations by product id'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getProductDispatchAllocations
);


// GET READY FOR DISPATCH ORDERS
router.get(
  "/ready-dispatch",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get ready for dispatch orders'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getReadyForDispatch
);


// RUN AUTO STOCK ALLOCATION
// router.post(
//   "/run-auto-allocation",
//   authenticate,

//   // #swagger.tags = ['Dispatch']
//   // #swagger.summary = 'Run automatic stock allocation'
//   // #swagger.security = [{ "bearerAuth": [] }]

//   dispatchController.runAutoAllocation
// );


// CREATE NEW SHIPMENT
router.post(
  "/create-shipment",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Create new shipment'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.createShipment
);


// MANUAL STOCK ALLOCATION
router.post(
  "/manual-allocation",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Allocate stock manually'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.manualAllocateStock
);


// CANCEL STOCK ALLOCATION
router.post(
  "/cancel-allocation",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Cancel stock allocation'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.cancelAllocation
);


// GET SINGLE ALLOCATION DETAILS
router.get(
  "/allocation-details/:allocationId",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get allocation details'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getAllocationDetails
);


// GET ALL DISPATCHED SHIPMENTS
router.get(
  "/dispatched",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get all dispatched shipments'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getDispatchedShipments
);


// GET SINGLE SHIPMENT DETAILS
router.get(
  "/shipment-details/:id",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get shipment details by id'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getShipmentById
);


// APPROVE SHIPMENT
router.put(
  "/:id/approve",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Approve shipment'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.approveShipment
);


router.get('/shipments',  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get shipment by sales order id'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getAllShipments
);
// GET SHIPMENT BY SALES ORDER
router.get(
  "/shipment-by/:salesOrderId",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get shipment by sales order id'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getShipmentBySalesOrderId
);

router.get("/approvals", authenticate, (req,res) =>{
    dispatchController.getShipmentApprovals(req,res);
})


// router.post(
//   "/create",
//   authenticate,

//   // #swagger.tags = ['Dispatch']
//   // #swagger.summary = 'Create new shipment'
//   // #swagger.security = [{ "bearerAuth": [] }]

//   dispatchController.createPartialShipment
// );

// router.post(
//   "/complete",
//   authenticate,

//   // #swagger.tags = ['Dispatch']
//   // #swagger.summary = 'Create new shipment'
//   // #swagger.security = [{ "bearerAuth": [] }]

//   dispatchController.completeShipment
// );



router.get(
  "/queue",
  authenticate,

  // #swagger.tags = ['Dispatch']
  // #swagger.summary = 'Get allocation details'
  // #swagger.security = [{ "bearerAuth": [] }]

  dispatchController.getCombinedDispatchQueue
);

module.exports = router;