/**
 * preflight-report.ts
 *
 * Formatter: pretty-prints per-agent preflight results with status icons
 * and a final summary line. Pure function -- no I/O.
 *
 * F-NEW-PRODUCT-AGENT-DIR-WRAPPER slice 4
 * @connexum/ai-governance
 */
// ---------------------------------------------------------------------------
// ANSI colour helpers (used only when colours are enabled)
// ---------------------------------------------------------------------------
const ANSI = {
    reset: '\x1b[0m',
    green: '\x1b[32m',
    red: '\x1b[31m',
    yellow: '\x1b[33m',
    cyan: '\x1b[36m',
    bold: '\x1b[1m',
    dim: '\x1b[2m',
};
function c(text, colour, useColour) {
    if (!useColour)
        return text;
    return `${ANSI[colour]}${text}${ANSI.reset}`;
}
export function statusDisplay(status) {
    switch (status) {
        case 'ok':
            return { icon: '[ok]', label: 'GOVERNED', colour: 'green' };
        case 'denied':
            return { icon: '[denied]', label: 'GOVERNED', colour: 'yellow' };
        case 'error':
            return { icon: '[error]', label: 'FAILED', colour: 'red' };
        case 'skipped':
            return { icon: '[skip]', label: 'SKIPPED', colour: 'dim' };
        case 'pending':
            return { icon: '[pending]', label: 'PENDING', colour: 'cyan' };
        default:
            return { icon: '[?]', label: 'UNKNOWN', colour: 'dim' };
    }
}
// ---------------------------------------------------------------------------
// Per-agent line
// ---------------------------------------------------------------------------
export function formatAgentLine(result, useColour) {
    const { icon, label, colour } = statusDisplay(result.status);
    const iconStr = c(icon, colour, useColour);
    const labelStr = c(`[${label}]`, colour, useColour);
    const fileStr = c(result.filePath, 'bold', useColour);
    const idStr = c(`(${result.agentId})`, 'dim', useColour);
    const provStr = result.provider
        ? c(`provider=${result.provider}`, 'dim', useColour)
        : c('provider=unknown', 'dim', useColour);
    const fwStr = result.framework
        ? c(` framework=${result.framework}`, 'dim', useColour)
        : '';
    return `  ${iconStr} ${fileStr} ${idStr} ${provStr}${fwStr} ${labelStr}`;
}
// ---------------------------------------------------------------------------
// Detail line (indented, only when there is a message to show)
// ---------------------------------------------------------------------------
export function formatDetailLine(result, useColour) {
    if (!result.detail)
        return null;
    return `       ${c(result.detail, 'dim', useColour)}`;
}
export function computeSummary(results) {
    let governed = 0, denied = 0, errors = 0, skipped = 0, pending = 0;
    for (const r of results) {
        if (r.status === 'ok')
            governed++;
        if (r.status === 'denied') {
            governed++;
            denied++;
        }
        if (r.status === 'error')
            errors++;
        if (r.status === 'skipped')
            skipped++;
        if (r.status === 'pending')
            pending++;
    }
    return { total: results.length, governed, denied, errors, skipped, pending };
}
export function formatSummaryLine(summary, useColour) {
    const parts = [];
    const govStr = c(`${summary.governed} governed successfully`, 'green', useColour);
    parts.push(govStr);
    if (summary.denied > 0) {
        parts.push(c(`${summary.denied} rule-blocked (still governed)`, 'yellow', useColour));
    }
    if (summary.errors > 0) {
        parts.push(c(`${summary.errors} need manual review`, 'red', useColour));
    }
    if (summary.skipped > 0) {
        parts.push(c(`${summary.skipped} skipped (unsupported provider)`, 'dim', useColour));
    }
    if (summary.pending > 0) {
        parts.push(c(`${summary.pending} pending (sidecar unreachable)`, 'cyan', useColour));
    }
    return (c(`${summary.total} agents detected, `, 'bold', useColour) +
        parts.join(', '));
}
/**
 * Format the full preflight report as a string suitable for stdout.
 */
export function formatPreflightReport(results, opts = {}) {
    const useColour = opts.useColour ?? false;
    const showDetail = opts.showDetail !== false;
    const header = opts.header ?? 'Preflight report';
    const lines = [];
    lines.push('');
    lines.push(c(`=== ${header} ===`, 'bold', useColour));
    lines.push('');
    if (results.length === 0) {
        lines.push(c('  No agents to check.', 'dim', useColour));
    }
    else {
        for (const r of results) {
            lines.push(formatAgentLine(r, useColour));
            if (showDetail) {
                const detail = formatDetailLine(r, useColour);
                if (detail)
                    lines.push(detail);
            }
        }
    }
    lines.push('');
    const summary = computeSummary(results);
    lines.push(formatSummaryLine(summary, useColour));
    lines.push('');
    return lines.join('\n');
}
//# sourceMappingURL=preflight-report.js.map