// engine/otel-requirements/metrics-requirements.ts — SPEC-044
// Generates acceptance criteria for OTel metrics based on service type.
/**
 * Generate metrics criteria for an HTTP API service.
 * RED metrics: Rate, Errors, Duration.
 */
export function generateHttpApiMetricsCriteria() {
    return [
        'El histograma `http.server.request.duration` registra la duración de todos los requests con percentiles P50/P95/P99',
        'El histograma incluye dimensiones `http.method`, `http.status_code` y `http.route` como atributos',
        'El counter `http.server.active_requests` refleja el número de requests en vuelo en cada momento',
    ];
}
/**
 * Generate metrics criteria for queue worker services.
 */
export function generateQueueWorkerMetricsCriteria() {
    return [
        'El histograma `queue.message.processing.duration` registra el tiempo de procesamiento por mensaje con dimensión `queue.name`',
        'El counter `queue.messages.failed` registra mensajes fallidos con dimensiones `queue.name` y `error.type`',
        'El gauge `queue.depth` refleja el número de mensajes pendientes por queue en cada momento',
    ];
}
/**
 * Generate metrics criteria for gRPC services.
 */
export function generateGrpcMetricsCriteria() {
    return [
        'El histograma `grpc.server.duration` registra la duración de llamadas gRPC con atributos `grpc.method` y `grpc.status_code`',
        'El counter `grpc.server.requests_total` registra el total de llamadas por método y código de estado',
    ];
}
/**
 * Detect the service type from project stack and external services.
 */
export function detectServiceType(stack, externalServices) {
    const all = [
        ...stack.map((s) => s.toLowerCase()),
        ...externalServices.map((s) => s.toLowerCase()),
    ];
    const hasGrpc = all.some((s) => s.includes('grpc') || s.includes('.proto'));
    if (hasGrpc) {
        return 'grpc-service';
    }
    const hasQueue = all.some((s) => s.includes('kafka') ||
        s.includes('rabbitmq') ||
        s.includes('sqs') ||
        s.includes('bull') ||
        s.includes('celery') ||
        s.includes('nats'));
    if (hasQueue) {
        return 'queue-worker';
    }
    const hasHttp = all.some((s) => s.includes('express') ||
        s.includes('fastapi') ||
        s.includes('django') ||
        s.includes('gin') ||
        s.includes('nestjs') ||
        s.includes('hono') ||
        s.includes('spring') ||
        s.includes('rails'));
    if (hasHttp) {
        return 'http-api';
    }
    return 'generic';
}
/**
 * Generate metrics criteria based on detected service type.
 */
export function generateMetricsCriteriaForType(serviceType) {
    switch (serviceType) {
        case 'http-api':
            return generateHttpApiMetricsCriteria();
        case 'queue-worker':
            return generateQueueWorkerMetricsCriteria();
        case 'grpc-service':
            return generateGrpcMetricsCriteria();
        case 'generic':
            return generateHttpApiMetricsCriteria(); // default to HTTP API metrics
    }
}
/**
 * Format criteria as HU.md checkbox lines.
 */
export function formatAsCriteria(criteria) {
    return criteria.map((c) => `- [ ] ${c}`);
}
/**
 * Build the metrics section for a HU.md file based on service type.
 */
export function buildOtelMetricsSection(serviceType) {
    const criteria = generateMetricsCriteriaForType(serviceType);
    if (criteria.length === 0) {
        return [];
    }
    return ['', '## Observabilidad — Métricas', '', ...formatAsCriteria(criteria)];
}
//# sourceMappingURL=metrics-requirements.js.map