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

// Agent checkin — no JWT, uses X-Agent-Key header
router.post('/checkin', ctrl.checkin);

// Schneller Announcement-Poll (leichtgewichtig, alle 15 Sek)
router.post('/announcements-poll', ctrl.announcementsPoll);

// Agent self-update script download — X-Agent-Key auth
router.get('/agent-script', ctrl.downloadScript);

// Announcement Watcher Script download — X-Agent-Key auth
router.get('/ann-watcher', ctrl.downloadAnnWatcher);

// Agent Setup EXE download — public, kein Auth nötig
router.get('/agent-setup', ctrl.downloadSetup);

// Dashboard endpoints — require JWT + admin
router.use(authenticateToken);
router.get('/statistics', requireAdmin, ctrl.getStatistics);
router.get('/', requireAdmin, ctrl.getAll);
router.get('/:id', requireAdmin, ctrl.getById);
router.delete('/:id', requireAdmin, ctrl.deleteAgent);

module.exports = router;
