const express = require('express');
const router = express.Router();
const FidoKeyController = require('../controllers/fidoKey.controller');
const { authenticateToken } = require('../middleware/auth');
const { canViewFidoKeys, canModifyFidoKeys, requireAdmin } = require('../middleware/roleCheck');

// All FIDO key routes require authentication
router.use(authenticateToken);

// Statistics (all authenticated users can view)
router.get('/stats', canViewFidoKeys, FidoKeyController.getStatistics);

// View routes (all authenticated users can view)
router.get('/', canViewFidoKeys, FidoKeyController.getAllKeys);
router.get('/status/:status', canViewFidoKeys, FidoKeyController.getKeysByStatus);
router.get('/serial/:serialNumber', canViewFidoKeys, FidoKeyController.getKeyBySerial);
router.get('/:id', canViewFidoKeys, FidoKeyController.getKeyById);

// Modification routes (Super Admin, Admin, Bearbeiter)
router.post('/', canModifyFidoKeys, FidoKeyController.createKey);
router.put('/:id', canModifyFidoKeys, FidoKeyController.updateKey);
router.put('/:id/status', canModifyFidoKeys, FidoKeyController.updateKeyStatus);

// Delete route (Super Admin and Admin only)
router.delete('/:id', requireAdmin, FidoKeyController.deleteKey);

module.exports = router;
