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

/**
 * @swagger
 * tags:
 *   name: Leave
 *   description: Leave management APIs
 */

router.post("/create", authenticate, authorize(["user", "admin", "doctor"]), (req, res) => {
    // #swagger.tags = ['Leave']
    // #swagger.summary = 'Create leave request'
    // #swagger.description = 'Create a new leave request by employee'
    // #swagger.security = [{ "bearerAuth": [] }]
    return leaveController.createLeave(req, res);
});

router.get("/", authenticate, authorize(["admin", "doctor", "employee", "user"]), (req, res) => {
    // #swagger.tags = ['Leave']
    // #swagger.summary = 'Get leaves'
    // #swagger.description = 'Get all leave requests. Admins can see all, employees see their own.'
    // #swagger.security = [{ "bearerAuth": [] }]
    return leaveController.getLeaves(req, res);
})

router.put("/:id", authenticate, authorize(["admin", "superadmin"]), (req, res) => {
    // #swagger.tags = ['Leave']
    // #swagger.summary = 'Update leave request'
    // #swagger.description = 'Update a leave request by ID. Only admins and superadmins can update.'
    // #swagger.security = [{ "bearerAuth": [] }]
    return leaveController.updateLeave(req, res);
})

router.delete("/:id", authenticate, authorize(["user", "admin", "superadmin"]), (req, res) => {
    // #swagger.tags = ['Leave']
    // #swagger.summary = 'Delete leave request'
    // #swagger.description = 'Delete a leave request by ID. Employees can delete their own, admins and superadmins can delete any.'
    // #swagger.security = [{ "bearerAuth": [] }]
    return leaveController.deleteLeave(req, res);
})

router.get("/:id",authenticate,authorize(["user", "manager", "admin"]), (req,res) => {
    // #swagger.tags = ['Leave']
    // #swagger.summary = 'Get leave by ID'
    // #swagger.description = 'Get a leave request by its ID.'
    // #swagger.security = [{ "bearerAuth": [] }]

    leaveController.getLeaveById(req,res);
}
  
);


module.exports = router;