export function buildJsonReport(results) {
    return {
        valid: results.every((result) => result.valid),
        tenants: results.map((result) => ({
            id: result.id,
            valid: result.valid,
            files: result.files,
            errors: result.errors.map((error) => ({
                file: error.file,
                path: error.path,
                message: error.message,
            })),
        })),
        summary: {
            tenants: results.length,
            files: results.reduce((sum, result) => sum + result.files, 0),
            errors: results.reduce((sum, result) => sum + result.errors.length, 0),
        },
    };
}
export function formatTextReport(scope, rootPath, results) {
    const header = scope === "tenants"
        ? `Validating tenant configuration root: ${rootPath}`
        : `Validating tenant configuration: ${rootPath}`;
    const lines = [header, "", ...results.flatMap(formatTenantBlock), formatSummaryLine(results)];
    return `${lines.join("\n")}\n`;
}
function formatTenantBlock(result) {
    const lines = [`${result.valid ? "PASS" : "FAIL"} ${result.id}`];
    if (result.valid) {
        for (const [resourceType, count] of Object.entries(result.resourceCounts)) {
            lines.push(`  ${count} ${pluralize(resourceType, count)}`);
        }
    }
    else {
        lines.push(...formatTenantErrors(result.errors));
    }
    lines.push("");
    return lines;
}
function formatTenantErrors(errors) {
    const lines = [];
    for (const [file, issues] of groupErrorsByFile(errors)) {
        lines.push(`  ${file}`);
        for (const issue of issues) {
            lines.push(`    ${formatIssueMessage(issue)}`);
        }
    }
    return lines;
}
function formatIssueMessage(issue) {
    return issue.path ? `${issue.path}: ${issue.message}` : issue.message;
}
function formatSummaryLine(results) {
    const totalFiles = results.reduce((sum, result) => sum + result.files, 0);
    const totalErrors = results.reduce((sum, result) => sum + result.errors.length, 0);
    if (totalErrors === 0) {
        return `Validated ${results.length} tenant(s) and ${totalFiles} configuration file(s).\nNo errors found.`;
    }
    const failedTenants = results.filter((result) => !result.valid).length;
    return `Validation failed: ${totalErrors} error(s) in ${failedTenants} tenant(s).`;
}
function groupErrorsByFile(errors) {
    const grouped = new Map();
    for (const error of errors) {
        const existing = grouped.get(error.file);
        if (existing) {
            existing.push(error);
            continue;
        }
        grouped.set(error.file, [error]);
    }
    return Array.from(grouped.entries());
}
function pluralize(label, count) {
    return count === 1 ? label : `${label}s`;
}
//# sourceMappingURL=report.js.map