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

// ==================== GET MODULE NAMES ====================

// Get all active module names with full details
router.get("/modules", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Module Types']
    #swagger.summary = 'Get all active module names'
    #swagger.description = 'Returns list of all active modules with id, name, code, description'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.responses[200] = {
      description: 'Modules fetched successfully',
      schema: {
        success: true,
        data: [{
          id: 1,
          module_name: "Purchase Order",
          module_code: "PO",
          description: "Purchase Order Management",
          is_active: true
        }],
        count: 1
      }
    }
  */
  moduleController.getModuleNames(req, res);
});

// Get only module names and codes (minimal version - for dropdowns)
router.get("/modules/simple", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Module Types']
    #swagger.summary = 'Get simple module names (id, name, code only)'
    #swagger.description = 'Returns minimal module data for dropdowns and select inputs'
    #swagger.security = [{ "bearerAuth": [] }]
    #swagger.responses[200] = {
      description: 'Modules fetched successfully',
      schema: {
        success: true,
        data: [{
          id: 1,
          module_name: "Purchase Order",
          module_code: "PO"
        }],
        count: 1
      }
    }
  */
  moduleController.getSimpleModuleNames(req, res);
});

// Get module by ID
router.get("/modules/:id", authenticate, (req, res) => {
  /*
    #swagger.tags = ['Module Types']
    #swagger.summary = 'Get module by ID'
    #swagger.security = [{ "bearerAuth": [] }]
  */
  moduleController.getModuleById(req, res);
});

module.exports = router;