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

// router.post(
//   "/create",
//   upload.fields([
//     { name: "invoiceFiles" },
//     { name: "idProofFiles" },
//     { name: "deliveryFiles" },
//     { name: "materialFiles" },
//   ]),
//   authenticate,
//   authorize(["admin", "qc", "security"]),
//   (req, res) => {
//     vehicleController.createVehicleEntry(req, res);
//   },
// );

// router.get("/",  authenticate,
//   authorize(["admin", "qc", "security"]), (req, res) => {
//   vehicleController.getVehicles(req, res);
// });

// // router.put("/approve/:id", (req, res)=>{
// //     visitorController.approveVisitor(req, res);
// // });

// router.put("/exit/:id",  authenticate,
//   authorize(["admin", "qc", "security"]), (req, res) => {
//   vehicleController.markVehicleExit(req, res);
// });

// module.exports = router;

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

/**
 * @swagger
 * tags:
 *   name: Commercial Vehicles
 *   description: Commercial vehicle entry, approval and exit APIs
 */


router.post(
  "/create",
  // upload.fields([
  //   { name: "invoiceFiles" },
  //   { name: "idProofFiles" },
  //   { name: "deliveryFiles" },
  //   { name: "materialFiles" },
  // ]),
  authenticate,
  authorize(["admin", "qc", "security"]),
  (req, res) => {

    /*
      #swagger.tags = ['Commercial Vehicles']
      #swagger.summary = 'Create commercial vehicle gate entry'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.consumes = ['multipart/form-data']

      #swagger.parameters['vehicleNumber'] = {
        in: 'formData',
        type: 'string',
        required: true,
        example: 'TS09AB1234'
      }

      #swagger.parameters['driverName'] = {
        in: 'formData',
        type: 'string',
        example: 'Ramesh Kumar'
      }

      #swagger.parameters['vendorName'] = {
        in: 'formData',
        type: 'string',
        example: 'ABC Logistics'
      }

      #swagger.parameters['invoiceFiles'] = {
        in: 'formData',
        type: 'file'
      }

      #swagger.parameters['idProofFiles'] = {
        in: 'formData',
        type: 'file'
      }

      #swagger.parameters['deliveryFiles'] = {
        in: 'formData',
        type: 'file'
      }

      #swagger.parameters['materialFiles'] = {
        in: 'formData',
        type: 'file'
      }

    */

    vehicleController.createVehicleEntry(req, res);
  }
);


router.get(
  "/all",
  authenticate,
  authorize(["admin", "qc", "security"]),
  (req, res) => {

    /*
      #swagger.tags = ['Commercial Vehicles']
      #swagger.summary = 'Get all commercial vehicle entries'
      #swagger.security = [{ "bearerAuth": [] }]
    */

    vehicleController.getVehicles(req, res);
  }
);

router.get("/weighbridge/cards",  authenticate,(req, res) =>{

    /*
      #swagger.tags = ['Commercial Vehicles']
      #swagger.summary = 'Get commercial vehicle weightbridgecards'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    vehicleController.getWeighbridgeCards(req, res);

});


router.put(
  "/exit/:id",
  authenticate,
  authorize(["admin", "qc", "security"]),
  (req, res) => {

    /*
      #swagger.tags = ['Commercial Vehicles']
      #swagger.summary = 'Mark commercial vehicle exit from gate'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'string',
        example: '665f3f0c8f9b123456789abc'
      }
    */

    vehicleController.markVehicleExit(req, res);
  }
);



router.get(
  "/prefill/:vehicleNumber",
  authenticate,
  authorize(["admin", "qc", "security"]),
  (req, res) => {

    /*
      #swagger.tags = ['Commercial Vehicles']
      #swagger.summary = 'Get all commercial vehicle entries'
      #swagger.security = [{ "bearerAuth": [] }]
    */

    vehicleController.getVehiclePrefill(req, res);
  }
);


router.put("/update/:id", authenticate, 
  upload.fields([
    { name: "invoiceFiles" },
    { name: "idProofFiles" },
    { name: "deliveryFiles" },
    { name: "materialFiles" },
  ]),
  
  (req, res) => {

    /*
      #swagger.tags = ['Commercial Vehicles']
      #swagger.summary = 'Update vehicle entries by Id'
      #swagger.security = [{ "bearerAuth": [] }]
    */

    vehicleController.updateVehicleEntry(req, res);
  });

module.exports = router;
