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

/**
 * @swagger
 * tags:
 *   name: Appointments
 *   description: Appointment booking and management APIs
 */

router.post(
  "/book",
  authenticate,
  authorize(["admin", "superadmin", "manager", "receptionist"]),
  (req, res) => {
    /*
      #swagger.tags = ['Appointments']
      #swagger.summary = 'Book appointment for a patient'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    appointmentController.bookAppointment(req, res);
  }
);

router.get(
  "/",
  authenticate,
  authorize(["admin", "superadmin", "manager", "receptionist", "doctor"]),
  (req, res) => {
    /*
      #swagger.tags = ['Appointments']
      #swagger.summary = 'Get all appointments with filters'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    appointmentController.getAllAppointments(req, res);
  }
);

router.put(
  "/update/:id",
  authenticate,
  authorize(["admin", "superadmin", "manager", "receptionist", "doctor"]),
  (req, res) => {
    /*
      #swagger.tags = ['Appointments']
      #swagger.summary = 'Update appointment slot and time'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'string',
        example: '68f2a9c1c3a0a123456789ef'
      }
    */
    appointmentController.updateAppointment(req, res);
  }
);

router.put(
  "/visited/:id",
  authenticate,
  authorize(["admin", "superadmin", "manager", "receptionist", "doctor"]),
  (req, res) => {
    /*
      #swagger.tags = ['Appointments']
      #swagger.summary = 'Mark appointment as visited (Booked → Waiting)'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['id'] = {
        in: 'path',
        required: true,
        type: 'string',
        example: '68f2a9c1c3a0a123456789ef'
      }
    */
    appointmentController.markAsVisited(req, res);
  }
);

router.get(
  "/:id",
  authenticate,
  authorize(["admin", "superadmin", "manager", "receptionist", "doctor"]),
    (req, res) => {
    /*
      #swagger.tags = ['Appointments']
      #swagger.summary = 'Get single appointment by ID'
      #swagger.security = [{ "bearerAuth": [] }]    
    */
    appointmentController.getSingleAppointment(req, res);
  }
);

router.put("/cancel/:id", authenticate, authorize(["admin", "superadmin", "manager", "receptionist", "doctor"]), (req, res) => {
  /* 
    #swagger.tags = ['Appointments']
    #swagger.summary = 'Cancel appointment by ID'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  appointmentController.cancelAppointment(req, res);
}); 

module.exports = router;