/**
 * Narrative Report Types -- P4-AIR-01 / P4-AIR-03
 *
 * Core type surface for AI-generated audit narrative reports. Every AI-
 * authored section is signed with an AiProvenance record and sealed into
 * the tamper-evident audit chain before the report is returned to the
 * caller.
 *
 * Pack-binding primacy: NarrativeReport.frameworks lists the compliance
 * pack IDs that scoped the report. Every NarrativeSection.framework value
 * MUST appear in that list. Events not bound to those packs MUST NOT
 * appear in any section.
 *
 * Spec: P4-AIR-01 AC 5-6, P4-AIR-03 AC 7-9
 *
 * @connexum/ai-governance
 */
// ---------------------------------------------------------------------------
// Errors (P4-AIR-01 AC 18)
// ---------------------------------------------------------------------------
/**
 * Thrown when the LLM produces a factual claim referencing an event ID
 * that was not present in the input event batch. Thrown before any output
 * is returned (fail-closed).
 */
export class UncitedClaimError extends Error {
    inventedIds;
    sectionAnchor;
    constructor(inventedIds, sectionAnchor) {
        super(`Section "${sectionAnchor}" contains ${inventedIds.length} uncited event reference(s): ` +
            inventedIds.join(', '));
        this.name = 'UncitedClaimError';
        this.inventedIds = inventedIds;
        this.sectionAnchor = sectionAnchor;
    }
}
/**
 * Thrown when the audit chain does not contain the required event types
 * for a report to be generated. Raised before the LLM call is made.
 */
export class MissingEvidenceError extends Error {
    missingEventTypes;
    framework;
    constructor(missingEventTypes, framework) {
        super(`Framework "${framework}" requires event type(s) [${missingEventTypes.join(', ')}] ` +
            `but none were found in the audit window.`);
        this.name = 'MissingEvidenceError';
        this.missingEventTypes = missingEventTypes;
        this.framework = framework;
    }
}
/**
 * Thrown when renderNarrativeReport() is called on a report whose
 * provenance has not been sealed into the audit chain.
 */
export class MissingProvenanceError extends Error {
    reportId;
    constructor(reportId) {
        super(`Cannot render report "${reportId}": provenance has not been sealed into the audit chain. ` +
            `Call sealProvenanceToChain() before rendering.`);
        this.name = 'MissingProvenanceError';
        this.reportId = reportId;
    }
}
/**
 * Thrown by AuditNarrativeGenerator.generate() when the underlying audit
 * chain fails integrity verification before narrative generation begins.
 *
 * A report generated from a tampered chain is a false attestation. Fail-closed
 * is the only correct policy.
 *
 * The HTTP route catches this and returns HTTP 409 with:
 *   { "error": "chain_tamper_detected", "detail": { firstBadEventId, ... } }
 *
 * Spec: P1-TAMPER-C
 */
// Cross-module-identity brand. The root package is CJS-style ("type": "git",
// no "module") while packages/governance-server is "type":"module". Under tsx
// the same source file can be loaded into two distinct module records, which
// makes the constructor identity diverge so plain `instanceof` returns false
// across the boundary. The branded Symbol + custom hasInstance keeps a single
// logical identity for the error regardless of how many module copies exist.
const CHAIN_TAMPER_BRAND = Symbol.for('@connexum/ai-governance/ChainTamperDetectedError');
export class ChainTamperDetectedError extends Error {
    firstBadEventId;
    expectedHash;
    observedHash;
    brokenAt;
    [CHAIN_TAMPER_BRAND] = true;
    static brand = CHAIN_TAMPER_BRAND;
    static [Symbol.hasInstance](candidate) {
        return (typeof candidate === 'object' &&
            candidate !== null &&
            candidate[CHAIN_TAMPER_BRAND] === true);
    }
    constructor(detail) {
        super(`Audit chain integrity check failed before report generation. ` +
            `First bad event: "${detail.firstBadEventId}". ` +
            `Expected hash prefix: ${detail.expectedHash.slice(0, 16) || 'unknown'}, ` +
            `observed: ${detail.observedHash.slice(0, 16) || 'unknown'}.`);
        this.name = 'ChainTamperDetectedError';
        this.firstBadEventId = detail.firstBadEventId;
        this.expectedHash = detail.expectedHash;
        this.observedHash = detail.observedHash;
        this.brokenAt = detail.brokenAt ?? -1;
    }
}
//# sourceMappingURL=narrative-types.js.map