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

/**
 * @swagger
 * tags:
 *   name: Visitor Management Postgre
 *   description: Visitor gate entry, approval and exit APIs
 */


router.post(
  "/create",
  upload.single("photo"),
  authenticate,
  authorize(["admin", "qc", "security"]),
  (req, res) => {

    /*
      #swagger.tags = ['Visitors Management Postgre']
      #swagger.summary = 'Create visitor gate entry'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.consumes = ['multipart/form-data']

      #swagger.parameters['visitorName'] = {
        in: 'formData',
        required: true,
        type: 'string',
        example: 'Amit Kumar'
      }

      #swagger.parameters['mobileNumber'] = {
        in: 'formData',
        type: 'string',
        example: '9876543210'
      }

      #swagger.parameters['purpose'] = {
        in: 'formData',
        type: 'string',
        example: 'Meeting'
      }

      #swagger.parameters['hostName'] = {
        in: 'formData',
        type: 'string',
        example: 'Ravi Sharma'
      }

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

    visitorController.createVisitor(req, res);
  }
);


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

    /*
      #swagger.tags = [''Visitors Management Postgre']
      #swagger.summary = 'Get all visitor entries'
      #swagger.security = [{ "bearerAuth": [] }]
    */

    visitorController.getVisitors(req, res);
  }
);


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

    /*
      #swagger.tags = ['Visitors Management Postgre']
      #swagger.summary = 'Approve visitor entry by host'
      #swagger.security = [{ "bearerAuth": [] }]

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

    visitorController.approveVisitor(req, res);
  }
);


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

    /*
      #swagger.tags = ['Visitors Management Postgre']
      #swagger.summary = 'Mark visitor exit from gate'
      #swagger.security = [{ "bearerAuth": [] }]

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

    visitorController.markVisitorExit(req, res);
  }

  
);

router.delete("/:id",authenticate,authorize(["admin", "security"]),
  (req, res) =>{
    /*
      #swagger.tags = ['Visitors Management Postgre']
      #swagger.summary = 'Delete visitor by id'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    visitorController.deleteVisitor(req, res);
  }
);


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

    /*
      #swagger.tags = ['Visitors']
      #swagger.summary = 'Get visitor by Id entries'
      #swagger.security = [{ "bearerAuth": [] }]
    */

    visitorController.getVisitorById(req, res);
  }
);

module.exports = router;
