// engine/dora-metrics/benchmarks.ts — DORA benchmarks and tier classification (SPEC-033)
/** DORA benchmarks from State of DevOps report */
const BENCHMARKS = {
    deploymentFrequency: { elite: 7, high: 1, medium: 0.25 },
    leadTimeHours: { elite: 1, high: 24, medium: 168 },
    changeFailureRate: { elite: 5, high: 10, medium: 15 },
    mttrHours: { elite: 1, high: 24, medium: 168 },
};
/**
 * Classifies a single DORA metric against the State of DevOps benchmarks.
 * For frequency: higher is better. For time/rate: lower is better.
 */
export function classifyMetric(metricName, value) {
    const b = BENCHMARKS[metricName];
    if (metricName === 'deploymentFrequency') {
        if (value >= b.elite) {
            return 'elite';
        }
        if (value >= b.high) {
            return 'high';
        }
        if (value >= b.medium) {
            return 'medium';
        }
        return 'low';
    }
    else {
        if (value <= b.elite) {
            return 'elite';
        }
        if (value <= b.high) {
            return 'high';
        }
        if (value <= b.medium) {
            return 'medium';
        }
        return 'low';
    }
}
/**
 * Classifies the overall DORA tier as the worst (lowest) tier across all metrics.
 */
export function classifyTier(metrics) {
    const tierOrder = ['elite', 'high', 'medium', 'low'];
    const tiers = [
        classifyMetric('deploymentFrequency', metrics.deploymentFrequency),
        classifyMetric('leadTimeHours', metrics.leadTimeHours),
        classifyMetric('changeFailureRate', metrics.changeFailureRate),
        classifyMetric('mttrHours', metrics.mttrHours),
    ];
    let worstIndex = 0;
    for (const tier of tiers) {
        const idx = tierOrder.indexOf(tier);
        if (idx > worstIndex) {
            worstIndex = idx;
        }
    }
    /* v8 ignore start */
    return tierOrder[worstIndex] ?? 'low';
    /* v8 ignore stop */
}
/**
 * Generates actionable spec recommendations based on DORA metrics tier.
 */
export function generateRecommendations(metrics) {
    const recommendations = [];
    const dfTier = classifyMetric('deploymentFrequency', metrics.deploymentFrequency);
    const ltTier = classifyMetric('leadTimeHours', metrics.leadTimeHours);
    const cfrTier = classifyMetric('changeFailureRate', metrics.changeFailureRate);
    const mttrTier = classifyMetric('mttrHours', metrics.mttrHours);
    if (mttrTier === 'low' || mttrTier === 'medium') {
        recommendations.push('MTTR is high — consider spec: improve observability and alerting ' +
            '(distributed tracing, on-call runbooks, automated rollback)');
    }
    if (cfrTier === 'low' || cfrTier === 'medium') {
        recommendations.push('Change Failure Rate is high — consider spec: improve integration test coverage ' +
            'or introduce feature flags for safer gradual rollouts');
    }
    if (ltTier === 'low' || ltTier === 'medium') {
        recommendations.push('Lead Time is high — consider spec: improve CI/CD pipeline speed, ' +
            'reduce PR review cycle, or automate deployment steps');
    }
    if (dfTier === 'low' || dfTier === 'medium') {
        recommendations.push('Deployment Frequency is low — consider spec: decouple releases from deploys ' +
            'using feature flags, or reduce batch size of changes per deployment');
    }
    return recommendations;
}
//# sourceMappingURL=benchmarks.js.map