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

/**
 * @swagger
 * tags:
 *   name: Organizations
 *   description: Organization management APIs
 */

// CREATE organization (admin only)
router.post("/create", authenticate, authorize(["admin", "manager"]), (req, res) => {
  /* 
    #swagger.tags = ['Organizations']
    #swagger.summary = 'Create a new organization'
      #swagger.security = [{ "bearerAuth": [] }]
  */
  orgController.createOrg(req, res);
});



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

  orgController.getOrgs(req, res);
});

// GET org by ID (all logged in users)
router.get("/get/:id", authenticate, (req, res) => {
  // #swagger.tags = ['Organizations']
  // #swagger.summary = 'Get an organization by ID'
  // #swagger.security = [{ "bearerAuth": [] }]

  orgController.getOrgById(req, res);
});

// UPDATE org (admin only)
router.put("/update/:id", authenticate, authorize("admin"), (req, res) => {
  // #swagger.tags = ['Organizations']
  // #swagger.summary = 'Update an organization by ID'
  // #swagger.security = [{ "bearerAuth": [] }]

  orgController.updateOrg(req, res);
});

// DELETE org (admin only)
router.delete("/delete/:id", authenticate, authorize("admin"), (req, res) => {
  // #swagger.tags = ['Organizations']
  // #swagger.summary = 'Delete an organization by ID'
  // #swagger.security = [{ "bearerAuth": [] }]

  orgController.deleteOrg(req, res);
});

module.exports = router;
