import { Router } from 'express';
import serviceMonitorController from '../controllers/serviceMonitor.controller';
import { authenticate } from '../middleware/auth.middleware';
import { requirePermission } from '../middleware/rbac.middleware';

const router = Router();
const auth = [authenticate, requirePermission('admin:view')] as const;

// Static routes first (before parameterized :id routes)
router.get('/services/ping', ...auth, serviceMonitorController.pingAll.bind(serviceMonitorController));
router.get('/services/status-summary', ...auth, serviceMonitorController.getStatusSummary.bind(serviceMonitorController));
router.get('/services/:serviceId/ping-history', ...auth, serviceMonitorController.getPingHistory.bind(serviceMonitorController));
router.get('/services', ...auth, serviceMonitorController.getAll.bind(serviceMonitorController));
router.post('/services', ...auth, serviceMonitorController.create.bind(serviceMonitorController));
router.put('/services/:id', ...auth, serviceMonitorController.update.bind(serviceMonitorController));
router.delete('/services/:id', ...auth, serviceMonitorController.delete.bind(serviceMonitorController));
router.get('/system/health', ...auth, serviceMonitorController.getSystemHealth.bind(serviceMonitorController));
router.get('/users', ...auth, serviceMonitorController.getUsers.bind(serviceMonitorController));
router.post('/notifications/broadcast', ...auth, serviceMonitorController.broadcastNotification.bind(serviceMonitorController));
router.post('/notifications/broadcast/preview', ...auth, serviceMonitorController.broadcastPreview.bind(serviceMonitorController));

export default router;
