/**
 * Healthcare Compliance Bundle
 *
 * Orchestrates HIPAA and 42 CFR Part 2 compliance assessment with
 * evidence collection and audit trail verification.
 *
 * @module compliance/healthcare-bundle
 */
import { generateComplianceReport } from "./mapper.js";
import { formatHealthcareComplianceReportAsMarkdown } from "./report.js";
import { collectEvidence, storeEvidenceBundle } from "../evidence/index.js";
import { verifyHistoryIntegrity } from "../history/verify.js";
/**
 * Run a complete healthcare compliance assessment
 *
 * This function orchestrates:
 * 1. HIPAA Security Rule compliance mapping
 * 2. 42 CFR Part 2 compliance mapping
 * 3. Audit trail integrity verification (optional)
 * 4. Evidence bundle collection (optional)
 * 5. Combined report generation
 */
export async function runHealthcareComplianceAssessment(options) {
    const { projectPath, findings, certificationId, collectEvidence: shouldCollectEvidence = true, sign = false, verifyAuditTrail = true, storeEvidence = true, } = options;
    // Generate HIPAA report
    const hipaaReport = generateComplianceReport(findings, "HIPAA", projectPath, certificationId);
    // Generate 42 CFR Part 2 report
    const cfr42Report = generateComplianceReport(findings, "42-CFR-PART-2", projectPath, certificationId);
    // Calculate combined score
    const combinedScore = Math.round((hipaaReport.status.complianceScore + cfr42Report.status.complianceScore) / 2);
    // Determine overall status
    let status;
    if (combinedScore >= 90 &&
        hipaaReport.status.controlsNonCompliant === 0 &&
        cfr42Report.status.controlsNonCompliant === 0) {
        status = "compliant";
    }
    else if (combinedScore >= 70) {
        status = "at_risk";
    }
    else {
        status = "non_compliant";
    }
    // Verify audit trail if requested
    let auditVerification;
    if (verifyAuditTrail) {
        auditVerification = await verifyHistoryIntegrity(projectPath);
    }
    // Collect evidence if requested
    let evidenceBundle;
    let evidencePath;
    if (shouldCollectEvidence) {
        const evidenceResult = await collectEvidence({
            projectPath,
            certificationId,
            frameworks: ["HIPAA", "42-CFR-PART-2"],
            includeSbom: true,
            includeHistory: true,
            includeScanResults: true,
            includeConfig: true,
            sign,
        });
        if (evidenceResult.success && evidenceResult.bundle) {
            evidenceBundle = evidenceResult.bundle;
            // Store evidence if requested
            if (storeEvidence) {
                evidencePath = await storeEvidenceBundle(projectPath, evidenceBundle);
            }
        }
    }
    // Generate combined markdown report
    const markdownReport = formatHealthcareComplianceReportAsMarkdown(hipaaReport, cfr42Report, evidenceBundle, auditVerification);
    return {
        hipaaReport,
        cfr42Report,
        markdownReport,
        evidenceBundle,
        auditVerification,
        evidencePath,
        status,
        combinedScore,
    };
}
/**
 * Generate a quick healthcare compliance summary
 */
export function generateHealthcareComplianceSummary(result) {
    const statusIcon = result.status === "compliant" ? "✅" :
        result.status === "at_risk" ? "⚠️" : "❌";
    const lines = [
        `${statusIcon} Healthcare Compliance: ${result.status.toUpperCase()}`,
        `Combined Score: ${result.combinedScore}%`,
        `HIPAA: ${result.hipaaReport.status.complianceScore}%`,
        `42 CFR Part 2: ${result.cfr42Report.status.complianceScore}%`,
    ];
    if (result.auditVerification) {
        lines.push(`Audit Trail: ${result.auditVerification.verified ? "Verified" : "FAILED"}`);
    }
    if (result.evidenceBundle) {
        lines.push(`Evidence: ${result.evidenceBundle.id}`);
    }
    return lines.join(" | ");
}
//# sourceMappingURL=healthcare-bundle.js.map