import express from 'express';
import { requireAuth, requireRole } from '../middleware/auth.js';
import {
  getAllRoles,
  getActiveRoles,
  getRoleById,
  createRole,
  updateRole,
  deleteRole,
  getRolePermissions
} from '../controllers/userMasterController.js';

const router = express.Router();

// Get all roles (including inactive) - Super Admin only
router.get('/all', requireAuth, requireRole('SUPER_ADMIN'), getAllRoles);

// Get active roles only - All authenticated users
router.get('/active', requireAuth, getActiveRoles);

// Get role by ID - All authenticated users
router.get('/:id', requireAuth, getRoleById);

// Create new role - Super Admin only
router.post('/', requireAuth, requireRole('SUPER_ADMIN'), createRole);

// Update role - Super Admin only
router.put('/:id', requireAuth, requireRole('SUPER_ADMIN'), updateRole);

// Delete role (soft delete) - Super Admin only
router.delete('/:id', requireAuth, requireRole('SUPER_ADMIN'), deleteRole);

// Get role permissions - All authenticated users
router.get('/:id/permissions', requireAuth, getRolePermissions);

export default router;
