const express = require('express');
const {
  getAllRoles,
  getRole,
  createRole,
  updateRole,
  deleteRole,
  getAvailableModules,
  cloneRole
} = require('../controllers/roleController');
const { protect } = require('../middleware/auth');
const { checkModulePermission } = require('../middleware/checkPermission');

const router = express.Router();

router.use(protect);

router.get('/modules', getAvailableModules);
router.get('/', checkModulePermission('roles', 'read'), getAllRoles);
router.get('/:id', checkModulePermission('manage_roles'), getRole);
router.post('/', checkModulePermission('manage_roles'), createRole);
router.post('/:id/clone', checkModulePermission('manage_roles'), cloneRole);
router.patch('/:id', checkModulePermission('manage_roles'), updateRole);
router.delete('/:id', checkModulePermission('manage_roles'), deleteRole);

module.exports = router;