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

/**
 * @swagger
 * tags:
 *   name: Patients
 *   description: Patient management APIs
 */


router.post(
  "/create",
  authenticate,
  authorize(["admin", "superadmin"]),
  (req, res) => {
   /*
      #swagger.tags = ['Patients']
      #swagger.summary = 'Create a new patient'
      #swagger.security = [{ "bearerAuth": [] }]

      #swagger.parameters['body'] = {
        in: 'body',
        description: 'Patient information',
        required: true,
        schema: {
          name: 'John Doe',
          phone: '9876543210',
          email: 'john@example.com',
          address: 'Hyderabad, India',
          status: 'Active'
        }
      }
    */
    patientController.createPatient(req, res);
  }
);


router.get(
  "/",
  authenticate,
  authorize(["admin", "manager", "superadmin", "receptionist"]),
  (req, res) => {
    /*
      #swagger.tags = ['Patients']
      #swagger.summary = 'Get all patients'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['search'] = { in: 'query', type: 'string' }
      #swagger.parameters['page'] = { in: 'query', type: 'number' }
      #swagger.parameters['limit'] = { in: 'query', type: 'number' }
    */
    patientController.getPatients(req, res);
  }
);


router.get(
  "/:id",
  authenticate,
  authorize(["admin", "manager", "superadmin", "receptionist"]),
  (req, res) => {
    /*
      #swagger.tags = ['Patients']
      #swagger.summary = 'Get patient by ID'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = { description: 'Patient ID', required: true }
    */
    patientController.getPatientById(req, res);
  }
);


router.put(
  "/:id",
  authenticate,
  authorize(["admin", "manager", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Patients']
      #swagger.summary = 'Update patient details'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = { description: 'Patient ID', required: true }
    */
    patientController.updatePatient(req, res);
  }
);


router.delete(
  "/:id",
  authenticate,
  authorize(["admin", "manager", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Patients']
      #swagger.summary = 'Delete patient (soft delete)'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['id'] = { description: 'Patient ID', required: true }
    */
    patientController.deletePatient(req, res);
  }
);

module.exports = router;
