const express = require("express");
const router = express.Router();

const {
  createRole,
  getAllRoles,
  getRoleById,
  updateRole,
  deleteRole,
  toggleRoleStatus,
} = require("../../controllers/hrandpayrollsController/roleController");

const isAuthenticated = require("../../middlewares/authenticate");

/**
 * @swagger
 * tags:
 *   name: Roles
 *   description: Role management APIs
 */

/* ===========================
   ✅ CREATE ROLE
=========================== */
router.post("/create", isAuthenticated, (req, res) => {
  /*
    #swagger.tags = ['Roles']
    #swagger.summary = 'Create a new role'
    #swagger.security = [{ "bearerAuth": [] }]

    #swagger.requestBody = {
      required: true,
      content: {
        "application/json": {
          schema: {
            role_name: "HR Manager",
            description: "Handles HR operations"
          }
        }
      }
    }
  */
  createRole(req, res);
});

/* ===========================
   ✅ GET ALL ROLES
=========================== */
router.get("/get/all", isAuthenticated, (req, res) => {
  /*
    #swagger.tags = ['Roles']
    #swagger.summary = 'Get all roles'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  getAllRoles(req, res);
});

/* ===========================
   ✅ GET ROLE BY ID
=========================== */
router.get("/:id", isAuthenticated, (req, res) => {
  /*
    #swagger.tags = ['Roles']
    #swagger.summary = 'Get role by ID'
    #swagger.security = [{ "bearerAuth": [] }]

    #swagger.parameters['id'] = {
      in: 'path',
      required: true,
      type: 'integer',
      description: 'Role ID',
      example: 1
    }
  */
  getRoleById(req, res);
});

/* ===========================
   ✅ UPDATE ROLE
=========================== */
router.put("/:id", isAuthenticated, (req, res) => {
  /*
    #swagger.tags = ['Roles']
    #swagger.summary = 'Update role'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  updateRole(req, res);
});
/* ===========================
   ✅ TOGGLE ROLE STATUS
=========================== */
router.patch("/:id/toggle", isAuthenticated, (req, res) => {
  /*
    #swagger.tags = ['Roles']
    #swagger.summary = 'Toggle role status'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  toggleRoleStatus(req, res);
});

/* ===========================
   ✅ DELETE ROLE
=========================== */
router.delete("/:id", isAuthenticated, (req, res) => {
  /*
    #swagger.tags = ['Roles']
    #swagger.summary = 'Delete role'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  deleteRole(req, res);
});



module.exports = router;