"use strict";
/**
 * PolicyMatrix error hierarchy -- P4-RET-02
 *
 * Error classes thrown by PolicyMatrix when resolution fails or when
 * pack configuration is invalid at construction time.
 *
 * All errors extend RetentionError (which extends LlmProviderError) so
 * they sit in the unified error hierarchy and callers can use
 * `instanceof RetentionError` to catch all retention-engine errors.
 *
 * Error classes:
 *   PolicyMatrixError           -- base for all policy-matrix errors
 *   MissingRetentionPolicyError -- AC 20: no policy covers a tuple
 *   ConflictingContractTermsError -- two active terms disagree on same tuple
 *   InvalidPackRetentionError   -- malformed retentionPolicy at init
 *
 * Fail-closed philosophy: the engine never silently defaults to zero
 * retention. Missing policy = hard error. Conflicting terms = hard error.
 *
 * Spec: P4-RET-01 Section 2.2, AC 20
 *
 * @connexum/ai-governance
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvalidPackRetentionError = exports.ConflictingContractTermsError = exports.MissingRetentionPolicyError = exports.PolicyMatrixError = void 0;
const classifier_1 = require("./classifier");
// ---------------------------------------------------------------------------
// PolicyMatrixError -- base
// ---------------------------------------------------------------------------
/**
 * Base class for all errors originating from PolicyMatrix.
 * Catch this to handle any policy-matrix failure without knowing the subtype.
 */
class PolicyMatrixError extends classifier_1.RetentionError {
    constructor(opts) {
        super(opts);
        this.name = 'PolicyMatrixError';
    }
}
exports.PolicyMatrixError = PolicyMatrixError;
// ---------------------------------------------------------------------------
// MissingRetentionPolicyError -- AC 20
// ---------------------------------------------------------------------------
/**
 * Thrown when PolicyMatrix.resolve() finds no applicable policy for a
 * (tenantId, contractId, dataClass) tuple.
 *
 * Fail-closed: the write that created the record succeeded (classification
 * happened), but retention processing refuses to schedule or execute
 * deletion until an operator defines a policy covering this tuple.
 *
 * The dashboard should surface this as a coverage gap requiring operator
 * action before the next scheduled retention job.
 *
 * Spec: AC 20
 */
class MissingRetentionPolicyError extends PolicyMatrixError {
    tenantId;
    contractId;
    dataClass;
    constructor(tenantId, contractId, dataClass) {
        super({
            message: `MissingRetentionPolicyError: no retention policy covers tuple ` +
                `(tenantId="${tenantId}", contractId="${contractId}", dataClass="${dataClass}"). ` +
                `Define a ContractTerm, pack retentionPolicy, or system default before ` +
                `scheduling retention jobs for this data class.`,
            code: 'MISSING_RETENTION_POLICY',
        });
        this.name = 'MissingRetentionPolicyError';
        this.tenantId = tenantId;
        this.contractId = contractId;
        this.dataClass = dataClass;
    }
}
exports.MissingRetentionPolicyError = MissingRetentionPolicyError;
// ---------------------------------------------------------------------------
// ConflictingContractTermsError
// ---------------------------------------------------------------------------
/**
 * Thrown when two active ContractTerms cover the same
 * (tenantId, contractId, dataClass) tuple but specify different retention
 * parameters. This is an operator configuration error.
 *
 * The first two conflicting terms are attached for diagnostics.
 */
class ConflictingContractTermsError extends PolicyMatrixError {
    tenantId;
    contractId;
    dataClass;
    termA;
    termB;
    constructor(tenantId, contractId, dataClass, termA, termB) {
        super({
            message: `ConflictingContractTermsError: two active ContractTerms cover the same tuple ` +
                `(tenantId="${tenantId}", contractId="${contractId}", dataClass="${dataClass ?? 'null'}"). ` +
                `Each tuple may have at most one active ContractTerm. ` +
                `Deactivate or reconcile the conflicting terms before running retention.`,
            code: 'CONFLICTING_CONTRACT_TERMS',
        });
        this.name = 'ConflictingContractTermsError';
        this.tenantId = tenantId;
        this.contractId = contractId;
        this.dataClass = dataClass;
        this.termA = termA;
        this.termB = termB;
    }
}
exports.ConflictingContractTermsError = ConflictingContractTermsError;
// ---------------------------------------------------------------------------
// InvalidPackRetentionError
// ---------------------------------------------------------------------------
/**
 * Thrown at PolicyMatrix construction time when a CompliancePack has a
 * malformed retentionPolicy (e.g. negative retentionDays or missing
 * required fields). Fail-closed: the PolicyMatrix cannot be instantiated
 * with invalid pack configuration.
 */
class InvalidPackRetentionError extends PolicyMatrixError {
    packId;
    reason;
    constructor(packId, reason) {
        super({
            message: `InvalidPackRetentionError: pack "${packId}" has an invalid retentionPolicy. ` +
                `Reason: ${reason}. Fix the pack definition before constructing PolicyMatrix.`,
            code: 'INVALID_PACK_RETENTION',
        });
        this.name = 'InvalidPackRetentionError';
        this.packId = packId;
        this.reason = reason;
    }
}
exports.InvalidPackRetentionError = InvalidPackRetentionError;
//# sourceMappingURL=policy-matrix-errors.js.map