// const router = require("express").Router();
// const authenticate = require("../../middlewares/authenticate");
// const authorize = require("../../middlewares/authorize");
// const upload = require("../../middlewares/upload");
// const inwardController = require("../../controllers/postgre/inwardController");

// /**
//  * @swagger
//  * tags:
//  *   name: Inward Postgre
//  *   description: Inward material management APIs
//  */

// router.post(
//   "/create",
//   authenticate,
//   authorize(["admin", "warehouse", "security", "qc"]),
//   upload.array("deliveryFiles"),
//   (req, res) => {
//     /*
//       #swagger.tags = ['Inward']
//       #swagger.summary = 'Create inward entry (Manual)'
//       #swagger.security = [{ "bearerAuth": [] }]
//       #swagger.requestBody = 
//         required: true,
//         content: {
//           "application/json": {
//             schema: {
//               productName: "Urea",
//               referenceNo: "INV-5001",
//               vendorName: "ABC Traders",
//               totalQuantity: 12000,
//               quantityUnit: "Kg",
//               deliveryType: "Road",
//               trackingNumber: "TRK-9900",
//               personToReceive: "Ravi",
//               locationBlock: "Block A",
//               inwardStatus: "Pending",
//               isReturnable: false
//             }
//           }
//         }
//       }
//     */
//     inwardController.createInward(req, res);
//   }
// );

// router.get(
//   "/list",
//   authenticate,
//   authorize(["admin", "warehouse", "security", "qc"]),
//   (req, res) => {
//     /*
//       #swagger.tags = ['Inward']
//       #swagger.summary = 'Get inward list'
//       #swagger.security = [{ "bearerAuth": [] }]
//       #swagger.parameters['page'] = { in: 'query', example: 1 }
//       #swagger.parameters['limit'] = { in: 'query', example: 10 }
//       #swagger.parameters['search'] = { in: 'query', example: 'INV' }
//       #swagger.parameters['status'] = { in: 'query', example: 'Pending' }
//       #swagger.parameters['sortBy'] = { in: 'query', example: 'createdAt' }
//       #swagger.parameters['order'] = { in: 'query', example: 'desc' }
//     */
//     inwardController.getInwardList(req, res);
//   }
// );


// router.delete(
//   "/delete/:id",
//   authenticate,
//   // authorize(["admin", "warehouse"]),
//   (req, res) => {
//     /*
//       #swagger.tags = ['Inward']
//       #swagger.summary = 'Soft delete inward entry'
//       #swagger.security = [{ "bearerAuth": [] }]
//     */
//     inwardController.deleteInward(req, res);
//   }
// );

// router.get("/getBy/:id",
//   authenticate,
//   // authorize(["admin", "warehouse", "security", "qc"]),
//   (req, res) => {
//     /*
//       #swagger.tags = ['Inward']
//       #swagger.summary = 'Get inward details by id'
//       #swagger.security = [{ "bearerAuth": [] }]
//       #swagger.parameters['id'] = {
//         in: 'path',
//         required: true,
//         example: '66f2a3c4e9b123456789abcd'
//       }
//     */
//     inwardController.getInwardById(req, res);
//   }
// );

// router.put(
//   "/update/:id",
//   authenticate,
//   authorize(["admin", "warehouse"]),
//   upload.array("deliveryFiles", 10),
//   (req, res) => {
//     /*
//       #swagger.tags = ['Inward']
//       #swagger.summary = 'Update manual inward entry'
//       #swagger.security = [{ "bearerAuth": [] }]
//       #swagger.parameters['id'] = {
//         in: 'path',
//         required: true,
//         example: '66f2a3c4e9b123456789abcd'
//       }
//       #swagger.requestBody = {
//         required: true,
//         content: {
//           "multipart/form-data": {
//             schema: {
//               productName: "Urea",
//               referenceNo: "INV-5001",
//               vendorName: "ABC Traders",
//               totalQuantity: 15000,
//               quantityUnit: "Kg",
//               deliveryType: "Road",
//               personToReceive: "Ravi",
//               locationBlock: "Block B",
//               isReturnable: false,
//               deliveryFiles: [
//                 { type: "string", format: "binary" }
//               ]
//             }
//           }
//         }
//       }
//     */
//     inwardController.updateInward(req, res);
//   }
// );

// module.exports = router;

const router = require("express").Router();
const authenticate = require("../../middlewares/authenticate");
const authorize = require("../../middlewares/authorize");
const upload = require("../../middlewares/upload");
const inwardController = require("../../controllers/inventory/inwardController");

/**
 * @swagger
 * tags:
 *   name: Inward Postgre
 *   description: Inward material management APIs
 */

router.post(
  "/create",
  authenticate,
  authorize(["admin", "warehouse", "security", "qc"]),
  upload.array("deliveryFiles"),
  (req, res) => {
    inwardController.createInward(req, res);
  }
);

router.get(
  "/list",
  authenticate,
  authorize(["admin", "warehouse", "security", "qc"]),
  (req, res) => {
    inwardController.getInwardList(req, res);
  }
);

router.delete(
  "/delete/:id",
  authenticate,
  (req, res) => {
    inwardController.deleteInward(req, res);
  }
);

router.get(
  "/getBy/:id",
  authenticate,
  (req, res) => {
    inwardController.getInwardById(req, res);
  }
);

router.put(
  "/update/:id",
  authenticate,
  authorize(["admin", "warehouse"]),
  upload.array("deliveryFiles", 10),
  (req, res) => {
    inwardController.updateInward(req, res);
  }
);

// NEW: Approve inward route
router.post(
  "/approve/:id",
  authenticate,
  authorize(["admin", "warehouse"]),
  (req, res) => {
    inwardController.approveInward(req, res);
  }
);

// NEW: Reject inward route
router.post(
  "/reject/:id",
  authenticate,
  authorize(["admin", "warehouse"]),
  (req, res) => {
    inwardController.rejectInward(req, res);
  }
);

module.exports = router;