/**
 * Format audit result as Markdown for display in suggest_tooling output.
 */
export function formatDepAuditMarkdown(result) {
    const lines = ['## Dependency Audit', ''];
    lines.push(`**Ecosystem:** ${result.ecosystem}`);
    lines.push(`**Total deps:** ${result.totalDeps}`);
    lines.push(`**Summary:** ${result.summary}`);
    lines.push('');
    if (result.critical.length > 0) {
        lines.push('### Critical Issues');
        lines.push('');
        for (const entry of result.critical) {
            lines.push(`#### ${entry.name} @ ${entry.currentVersion}`);
            for (const vuln of entry.vulns) {
                const fixNote = vuln.fixedIn ? ` — fixed in ${vuln.fixedIn}` : ' — no fix available';
                lines.push(`- **[${vuln.severity.toUpperCase()}]** ${vuln.cveId}: ${vuln.description}${fixNote}`);
            }
            if (entry.license.compatibility === 'critical') {
                lines.push(`- **[LICENSE]** ${entry.license.reason}`);
            }
            if (entry.abandoned.isAbandoned) {
                lines.push(`- **[ABANDONED]** ${entry.abandoned.reason}`);
                if (entry.abandoned.suggestedAlternative) {
                    lines.push(`  - Alternative: ${entry.abandoned.suggestedAlternative}`);
                }
            }
            lines.push('');
        }
    }
    if (result.warnings.length > 0) {
        lines.push('### Warnings');
        lines.push('');
        for (const entry of result.warnings) {
            lines.push(`- **${entry.name}** @ ${entry.currentVersion}: ${buildEntryWarning(entry)}`);
        }
        lines.push('');
    }
    if (result.duplicates.length > 0) {
        lines.push('### Duplicate Dependencies');
        lines.push('');
        for (const dup of result.duplicates) {
            lines.push(`- **[${dup.category}]** ${dup.packages.join(', ')} — ${dup.recommendation}`);
        }
        lines.push('');
    }
    if (result.critical.length === 0 &&
        result.warnings.length === 0 &&
        result.duplicates.length === 0) {
        lines.push('_No issues detected._');
    }
    return lines.join('\n');
}
function buildEntryWarning(entry) {
    const parts = [];
    for (const vuln of entry.vulns) {
        const fix = vuln.fixedIn ? ` (fix: ${vuln.fixedIn})` : '';
        parts.push(`${vuln.cveId}${fix}`);
    }
    if (entry.license.compatibility === 'warning' || entry.license.compatibility === 'unknown') {
        parts.push(`license=${entry.license.license || 'unknown'}`);
    }
    if (entry.abandoned.isAbandoned) {
        parts.push('abandoned');
    }
    return parts.join('; ');
}
/**
 * Format a single dep audit entry as a spec acceptance criteria template (C5).
 * Useful for pre-checking a dep before adding it to a project.
 */
export function formatDepAuditAcceptanceCriteria(entry) {
    const lines = [
        `## Pre-check: \`${entry.name}\` @ ${entry.currentVersion}`,
        '',
        `**Ecosystem:** ${entry.ecosystem}`,
        `**License:** ${entry.license.license || 'unknown'} — ${entry.license.reason}`,
        `**Abandoned:** ${entry.abandoned.isAbandoned ? 'YES' : 'No'}`,
    ];
    if (entry.abandoned.isAbandoned && entry.abandoned.suggestedAlternative) {
        lines.push(`**Alternative:** ${entry.abandoned.suggestedAlternative}`);
    }
    if (entry.vulns.length > 0) {
        lines.push('');
        lines.push('**Known vulnerabilities:**');
        for (const vuln of entry.vulns) {
            const fixNote = vuln.fixedIn ? `fixed in ${vuln.fixedIn}` : 'no fix';
            lines.push(`- [${vuln.severity.toUpperCase()}] ${vuln.cveId}: ${vuln.description} (${fixNote})`);
        }
    }
    else {
        lines.push('**Vulnerabilities:** None known.');
    }
    lines.push('');
    lines.push('### Acceptance Criteria Template');
    lines.push('');
    const licenseOk = entry.license.compatibility === 'compatible';
    const vulnOk = entry.vulns.length === 0;
    const notAbandoned = !entry.abandoned.isAbandoned;
    lines.push(`- [ ] License is compatible: **${licenseOk ? 'PASS' : 'FAIL'}**`);
    lines.push(`- [ ] No critical vulnerabilities: **${vulnOk ? 'PASS' : 'FAIL'}**`);
    lines.push(`- [ ] Package is actively maintained: **${notAbandoned ? 'PASS' : 'FAIL'}**`);
    lines.push('- [ ] Reviewed in a spike and team approved adoption');
    return lines.join('\n');
}
//# sourceMappingURL=formatters.js.map