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

const restRequestsTotal = new Counter({
  name: 'pacifica_rest_requests_total',
  help: 'Pacifica REST requests',
  labelNames: ['endpoint', 'method', 'status']
});

const restLatencyMs = new Histogram({
  name: 'pacifica_rest_latency_ms',
  help: 'Pacifica REST latency in milliseconds',
  labelNames: ['endpoint', 'method'],
  buckets: [50, 100, 200, 500, 1000, 2000, 5000]
});

export interface RestMetricLabels {
  endpoint: string;
  method: string;
  status: number | string;
}

export function observeRestRequest(labels: RestMetricLabels, durationMs: number): void {
  restRequestsTotal.inc({
    endpoint: labels.endpoint,
    method: labels.method,
    status: String(labels.status)
  });
  restLatencyMs.observe({ endpoint: labels.endpoint, method: labels.method }, durationMs);
}
