// tools/create-spec-hu/otel-hu-adapter.ts — SPEC-044
// Builds the OTel observability section for HU.md criteria.
import { buildOtelTraceSection, buildOtelMetricsSection, buildSloSection, detectServiceType, hasImplicitSla, } from '../../engine/otel-requirements/index.js';
/**
 * Build the OTel observability section for feature/infra specs targeting backend/fullstack.
 * Emits trace propagation, metrics, and SLO criteria when OTel is installed or the project
 * has distributed patterns (external HTTP clients, queues).
 */
export function buildOtelHuSection(type, target, knowledge) {
    if (!knowledge) {
        return [];
    }
    if (type !== 'feature' && type !== 'infra') {
        return [];
    }
    if (target !== 'backend' && target !== 'fullstack') {
        return [];
    }
    const otel = knowledge.otelDetection;
    const hasOtel = otel?.isInstalled === true;
    const needsOtel = otel?.needsOtel === true;
    if (!hasOtel && !needsOtel) {
        return [];
    }
    const stackAndServices = [...knowledge.stack, ...knowledge.externalServices].map((s) => s.toLowerCase());
    const hasExternalClients = stackAndServices.some((s) => s.includes('axios') || s.includes('http') || s.includes('fetch') || s.includes('client'));
    const hasMessageQueue = stackAndServices.some((s) => s.includes('kafka') ||
        s.includes('rabbitmq') ||
        s.includes('sqs') ||
        s.includes('bull') ||
        s.includes('celery') ||
        s.includes('nats'));
    const serviceType = detectServiceType(knowledge.stack, knowledge.externalServices);
    const lines = [];
    lines.push(...buildOtelTraceSection(hasExternalClients, hasMessageQueue));
    lines.push(...buildOtelMetricsSection(serviceType));
    const apiContractTypes = knowledge.apiContracts.map((c) => c.type);
    if (hasImplicitSla(knowledge.stack, apiContractTypes)) {
        lines.push(...buildSloSection());
    }
    return lines;
}
//# sourceMappingURL=otel-hu-adapter.js.map