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

/**
 * @swagger
 * tags:
 *   name: ReturnableGoods
 *   description: Returnable goods management APIs
 */

router.post(
  "/create",
  authenticate,
  authorize(["admin", "security", "qc", "warehouse"]),
  upload.single("itemPhoto"),
  (req, res) => {
    /*
  #swagger.tags = ['ReturnableGoods']
  #swagger.summary = 'Create returnable goods'
  #swagger.security = [{ "bearerAuth": [] }]
  #swagger.requestBody = {
    required: true,
    content: {
      "application/json": {
        schema: {
          itemId: "OUT-001",
          itemName: "Tool Kit",
          quantity: 1,
          condition: "Good",
          remarks: "Handle carefully",
          pickupDate: "2026-03-06T10:00:00Z",
          returnDate: "2026-03-10T10:00:00Z",
          referenceBy: "USER_ID",
          receiverName: "Ravi Kumar",
          approvedBy: "MANAGER_ID"
        }
      }
    }
  }
*/
    goodsController.createReturnableGoods(req, res);
  },
);

router.get(
  "/list",
  authenticate,
   authorize(["admin", "security", "qc", "warehouse"]),
  (req, res) => {
    /*
      #swagger.tags = ['ReturnableGoods']
      #swagger.summary = 'Get returnable goods list'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['page'] = { in: 'query', example: 1 }
      #swagger.parameters['limit'] = { in: 'query', example: 10 }
    */
    goodsController.getReturnableGoods(req, res);
  }
);


router.get(
  "/getBy/:id",
  authenticate,
  //  authorize(["admin", "security", "qc", "warehouse"]),
  (req, res) => {
    /*
      #swagger.tags = ['ReturnableGoods']
      #swagger.summary = 'Get returnable goods byId'
      #swagger.security = [{ "bearerAuth": [] }]
     
    */
    goodsController.getReturnableGoodsById(req, res);
  }
);

router.put(
  "/update/:id",
  authenticate,
  upload.single("itemPhoto"),
  (req, res) => {
    /*
      #swagger.tags = ['ReturnableGoods']
      #swagger.summary = 'Update returnable goods'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = { in: 'path', required: true, example: '65f1c2ab1234567890abcd12' }
    */
    goodsController.updateReturnableGoods(req, res);
  }
);

router.put("/close/:id", authenticate,  (req, res) =>{
       /*
      #swagger.tags = ['ReturnableGoods']
      #swagger.summary = 'Update returnable goods status'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = { in: 'path', required: true, example: '65f1c2ab1234567890abcd12' }
    */
    goodsController.closeReturnableGoods(req, res);
  }
  
);


router.delete(
  "/delete/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['ReturnableGoods']
      #swagger.summary = 'Delete returnable goods'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = { in: 'path', required: true, example: '65f1c2ab1234567890abcd12' }
    */
    goodsController.deleteReturnableGoods(req, res);
  }
);

module.exports = router;
