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

/**
 * @swagger
 * tags:
 *   name: Designations
 *   description: Designation management APIs
 */

// CREATE designation (admin only)
router.post("/create", authenticate, authorize(["admin"]), (req, res) => {
  /* 
    #swagger.tags = ['Designations']
    #swagger.summary = 'Create a new designation'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['body'] = {
      in: 'body',
      description: 'Designation details including departmentId and orgId',
      required: true,
      schema: { 
        designationName: "Software Engineer", 
        departmentId: "64f5a2d8c9e4b3a1f0a12345",
        orgId: "64f5a2d8c9e4b3a1f0a67890"
      }
    }
  */
  designationController.createDesignation(req, res);
});

// GET all designations (admin + manager allowed)
router.get("/get/all", authenticate, authorize(["admin", "manager"]), (req, res) => {
  /* 
    #swagger.tags = ['Designations']
    #swagger.summary = 'Get all designations'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  designationController.getDesignations(req, res);
});

// GET designation by ID (all logged in users)
router.get("/get/:id", authenticate, (req, res) => {
  /* 
    #swagger.tags = ['Designations']
    #swagger.summary = 'Get a designation by ID'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['id'] = { description: 'Designation ID', required: true }
  */
  designationController.getDesignationById(req, res);
});

// UPDATE designation (admin only)
router.put("/update/:id", authenticate, authorize("admin"), (req, res) => {
  /* 
    #swagger.tags = ['Designations']
    #swagger.summary = 'Update a designation by ID'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['id'] = { description: 'Designation ID', required: true }
    #swagger.parameters['body'] = {
      in: 'body',
      description: 'Update data (designationName, departmentId, orgId, status)',
      required: true,
      schema: { 
        designationName: "Senior Engineer", 
        departmentId: "64f5a2d8c9e4b3a1f0a12345",
        orgId: "64f5a2d8c9e4b3a1f0a67890",
        status: true 
      }
    }
  */
  designationController.updateDesignation(req, res);
});

// DELETE designation (admin only)
router.delete("/delete/:id", authenticate, authorize("admin"), (req, res) => {
  /* 
    #swagger.tags = ['Designations']
    #swagger.summary = 'Delete a designation by ID'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['id'] = { description: 'Designation ID', required: true }
  */
  designationController.deleteDesignation(req, res);
});

router.get("/by-department/:departmentId",authenticate, authorize("admin"), (req, res) => {
  /* 
    #swagger.tags = ['Designations']
    #swagger.summary = 'Get a designation by Departement'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  designationController.getDesignationsByDepartment(req, res);
}
);

module.exports = router;
