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

const leaveGroupsController = require("../../controllers/hrandpayrollsController/leaveGroupsController");
const authenticate = require("../../middlewares/authenticate");

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

/* ===========================
   ✅ LIST (Dropdown)
=========================== */
router.get(
  "/list",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Leave Groups']
      #swagger.summary = 'List all leave groups (for dropdowns)'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    leaveGroupsController.getLeaveGroupsList(req, res);
  }
);

/* ===========================
   ✅ CREATE
=========================== */
router.post(
  "/create",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Leave Groups']
      #swagger.summary = 'Create a new leave group'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    leaveGroupsController.createLeaveGroup(req, res);
  }
);

/* ===========================
   ✅ GET ALL (with pagination)
=========================== */
router.get(
  "/all",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Leave Groups']
      #swagger.summary = 'Get all leave groups with pagination'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    leaveGroupsController.getAllLeaveGroups(req, res);
  }
);

/* ===========================
   ✅ GET BY ID
=========================== */
router.get(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Leave Groups']
      #swagger.summary = 'Get leave group by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    leaveGroupsController.getLeaveGroupById(req, res);
  }
);

/* ===========================
   ✅ UPDATE
=========================== */
router.put(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Leave Groups']
      #swagger.summary = 'Update a leave group'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    leaveGroupsController.updateLeaveGroup(req, res);
  }
);

/* ===========================
   ✅ TOGGLE STATUS
=========================== */
router.patch(
  "/:id/toggle",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Leave Groups']
      #swagger.summary = 'Toggle active/inactive status of a leave group'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    leaveGroupsController.toggleLeaveGroupStatus(req, res);
  }
);

/* ===========================
   ✅ DELETE
=========================== */
router.delete(
  "/:id",
  authenticate,
  (req, res) => {
    /*
      #swagger.tags = ['Leave Groups']
      #swagger.summary = 'Delete a leave group (soft delete)'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    leaveGroupsController.deleteLeaveGroup(req, res);
  }
);

module.exports = router;