const express = require('express');
const {
  getAllModules,
  getModule,
  getModulesByCategory,
  createModule,
  updateModule,
  deleteModule,
  toggleModuleStatus,
  reorderModules,
  getModuleStats,
  getAvailableActions,
  getModuleCategories
} = require('../controllers/moduleController');
const { protect } = require('../middleware/auth');
const { checkModulePermission } = require('../middleware/checkPermission');

const router = express.Router();

router.use(protect);

router.get('/actions', getAvailableActions);
router.get('/categories', getModuleCategories);
router.get('/stats', checkModulePermission('manage_modules'), getModuleStats);
router.get('/by-category', getModulesByCategory);
router.get('/', getAllModules);
router.get('/:id', getModule);
router.post('/', checkModulePermission('manage_modules'), createModule);
router.post('/reorder', checkModulePermission('manage_modules'), reorderModules);
router.patch('/:id/toggle', checkModulePermission('manage_modules'), toggleModuleStatus);
router.patch('/:id', checkModulePermission('manage_modules'), updateModule);
router.delete('/:id', checkModulePermission('manage_modules'), deleteModule);

module.exports = router;
