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


/**
 * @swagger
 * tags:
 *   name: Services
 *   description: Service management APIs
 */

// CREATE service (admin only)
router.post("/create", authenticate, authorize("admin"),  (req, res) => {
  /* 
    #swagger.tags = ['Services']
    #swagger.summary = 'Create a new service'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['body'] = {
      in: 'body',
      description: 'Service details including orgId',
      required: true,
      schema: { serviceName: "IT Service", orgId: "64f5a2d8c9e4b3a1f0a12345" }
    }
  */
  serviceController.createService(req, res);
});

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

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

// UPDATE service (admin only)
router.put("/update/:id", authenticate, authorize("admin"), (req, res) => {
  /* 
    #swagger.tags = ['Services']
    #swagger.summary = 'Update a service by ID'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.parameters['id'] = { description: 'Service ID', required: true }
    #swagger.parameters['body'] = {
      in: 'body',
      description: 'Update data (serviceName, status)',
      required: true,
      schema: { 
        serviceName: "HR Service",
        status: true 
      }
    }
  */
  serviceController.updateService(req, res);
});

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

module.exports = router;
