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

// CREATE
router.post(
  "/",
  authenticate,
  // authorize(["admin", "superadmin", "manager"]),
  (req, res) => {
    /*
      #swagger.tags = ['Group Master']
      #swagger.summary = 'Create a new group'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['body'] = {
        in: 'body',
        required: true,
        schema: {
          group_name: "Example Group",
          module_type: "ITEM",
          group_code: "G001"
        }
      }
    */
    groupMasterController.createGroup(req, res);
  }
);

// GET ALL (with pagination)
router.get(
  "/",
  authenticate,
  // authorize(["admin", "superadmin", "manager"]),
  (req, res) => {
    /*
      #swagger.tags = ['Group Master']
      #swagger.summary = 'Get all groups with pagination'
      #swagger.security = [{ "bearerAuth": [] }]
      #swagger.parameters['search'] = { in: 'query', type: 'string' }
      #swagger.parameters['page'] = { in: 'query', type: 'integer' }
      #swagger.parameters['limit'] = { in: 'query', type: 'integer' }
    */
    groupMasterController.getAllGroups(req, res);
  }
);

// GET ALL (without pagination - for dropdowns)
router.get(
  "/all",
  authenticate,
  // authorize(["admin", "superadmin", "manager"]),
  (req, res) => {
    /*
      #swagger.tags = ['Group Master']
      #swagger.summary = 'Get all groups without pagination'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    groupMasterController.getAllGroupsWithoutPagination(req, res);
  }
);

// GET BY MODULE TYPE
router.get(
  "/module/:moduleType",
  authenticate,
  // authorize(["admin", "superadmin", "manager"]),
  (req, res) => {
    /*
      #swagger.tags = ['Group Master']
      #swagger.summary = 'Get groups by module type'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    groupMasterController.getGroupsByModuleType(req, res);
  }
);

// GET BY ID
router.get(
  "/:id",
  authenticate,
  // authorize(["admin", "superadmin", "manager"]),
  (req, res) => {
    /*
      #swagger.tags = ['Group Master']
      #swagger.summary = 'Get group by ID'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    groupMasterController.getGroupById(req, res);
  }
);

// UPDATE
router.put(
  "/:id",
  authenticate,
  // authorize(["admin", "superadmin", "manager"]),
  (req, res) => {
    /*
      #swagger.tags = ['Group Master']
      #swagger.summary = 'Update group'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    groupMasterController.updateGroup(req, res);
  }
);

// SOFT DELETE
router.delete(
  "/:id",
  authenticate,
  // authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Group Master']
      #swagger.summary = 'Soft delete group'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    groupMasterController.deleteGroup(req, res);
  }
);

// HARD DELETE (optional)
router.delete(
  "/hard/:id",
  authenticate,
  // authorize(["admin", "superadmin"]),
  (req, res) => {
    /*
      #swagger.tags = ['Group Master']
      #swagger.summary = 'Hard delete group'
      #swagger.security = [{ "bearerAuth": [] }]
    */
    groupMasterController.hardDeleteGroup(req, res);
  }
);

module.exports = router;