"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatArchitectureHealthTrendLine = formatArchitectureHealthTrendLine;
exports.renderArchitectureHealthHistoryConsole = renderArchitectureHealthHistoryConsole;
exports.renderArchitectureHealthHistoryJson = renderArchitectureHealthHistoryJson;
function sortSnapshotsByTimestamp(snapshots) {
    return [...snapshots].sort((left, right) => left.generatedAtUtc.localeCompare(right.generatedAtUtc));
}
function formatArchitectureHealthTrendLine(trend) {
    if (trend.trendDirection === 'no-history' || trend.previousScore === undefined) {
        return 'Trend: no previous history';
    }
    const delta = trend.delta ?? 0;
    if (delta === 0) {
        return 'Trend: stable from previous snapshot';
    }
    const sign = delta > 0 ? '+' : '';
    return `Trend: ${sign}${delta} from previous snapshot (${trend.trendDirection})`;
}
function renderArchitectureHealthHistoryConsole(input) {
    const limit = input.limit ?? 20;
    const snapshots = sortSnapshotsByTimestamp(input.history.snapshots).slice(-Math.max(1, limit));
    const lines = [];
    lines.push('Architecture Health History');
    if (snapshots.length === 0) {
        lines.push('- (no snapshots)');
    }
    else {
        for (const snapshot of snapshots) {
            lines.push(`- ${snapshot.generatedAtUtc} | ${snapshot.overallScore}`);
        }
    }
    lines.push('');
    lines.push('Trend');
    lines.push(`Current: ${input.trend.currentScore}`);
    lines.push(`Previous: ${input.trend.previousScore !== undefined ? input.trend.previousScore : '(none)'}`);
    lines.push(`Delta: ${input.trend.delta !== undefined ? input.trend.delta : '(none)'}`);
    lines.push(`Direction: ${input.trend.trendDirection}`);
    return `${lines.join('\n')}\n`;
}
function renderArchitectureHealthHistoryJson(input) {
    const limit = input.limit ?? 20;
    const snapshots = sortSnapshotsByTimestamp(input.history.snapshots).slice(-Math.max(1, limit));
    return `${JSON.stringify({
        version: input.history.version,
        snapshotCount: input.history.snapshots.length,
        snapshots,
        trend: input.trend,
    }, null, 2)}\n`;
}
//# sourceMappingURL=architectureHealthHistoryReporter.js.map