import {
  Registry,
  Counter,
  Histogram,
  Gauge,
  collectDefaultMetrics,
} from 'prom-client';

export const registry = new Registry();
collectDefaultMetrics({ register: registry });

export const httpRequestCounter = new Counter({
  name: 'core_edu_requests_total',
  help: 'Total HTTP requests',
  labelNames: ['method', 'route', 'status'] as const,
});
registry.registerMetric(httpRequestCounter);

export const httpRequestDuration = new Histogram({
  name: 'core_edu_request_duration_seconds',
  help: 'HTTP request duration in seconds',
  labelNames: ['method', 'route', 'status'] as const,
  buckets: [0.005, 0.01, 0.05, 0.1, 0.5, 1, 5],
});
registry.registerMetric(httpRequestDuration);

export const outboxPendingGauge = new Gauge({
  name: 'core_edu_outbox_pending',
  help: 'Number of pending outbox messages',
});
registry.registerMetric(outboxPendingGauge);

export const outboxPublishedCounter = new Counter({
  name: 'core_edu_outbox_published_total',
  help: 'Total outbox messages published to Kafka',
  labelNames: ['eventType', 'topic'] as const,
});
registry.registerMetric(outboxPublishedCounter);
