const express = require('express');
const router = express.Router();
const ctrl = require('../controllers/risk.controller');
const { authenticateToken } = require('../middleware/auth');
const { requireAdmin } = require('../middleware/roleCheck');
const { asyncHandler } = require('../middleware/errorHandler');

router.use(authenticateToken);

router.get('/stats',  asyncHandler(ctrl.getStats));
router.get('/',       asyncHandler(ctrl.getAll));
router.post('/sync',  requireAdmin, asyncHandler(ctrl.sync));
router.post('/',      requireAdmin, asyncHandler(ctrl.create));
router.put('/:id',    requireAdmin, asyncHandler(ctrl.update));
router.delete('/:id', requireAdmin, asyncHandler(ctrl.remove));

module.exports = router;
