// IRU Metrics API Routes
// Routes for Prometheus metrics

import { Router } from 'express';
import { prometheusIntegrationService } from '@/core/iru/monitoring/prometheus-integration.service';
import { monitoringService } from '@/core/iru/monitoring.service';

const router = Router();

/**
 * @route GET /api/v1/iru/metrics
 * @desc Get Prometheus metrics
 * @access Public (for Prometheus scraping)
 */
router.get('/', async (req, res, next) => {
  try {
    // Get all service metrics
    const metrics = await monitoringService.getServiceHealth('all');
    
    // Format as Prometheus metrics
    const prometheusMetrics = prometheusIntegrationService.generateMetricsResponse([
      {
        serviceName: 'iru-service',
        metrics: [
          {
            name: 'dbis_iru_active_subscriptions',
            value: 0, // TODO: Get from database
          },
        ],
        timestamp: new Date(),
      },
    ]);

    res.set('Content-Type', 'text/plain');
    res.send(prometheusMetrics);
  } catch (error) {
    return next(error);
  }
});

export default router;
