/**
 * TtdMergeInspection — read-only protocol object for TTD merge panels.
 *
 * @module domain/services/merge/TtdMergeInspection
 */
import WarpError from "../../errors/WarpError.js";
import MergeClassification from "./MergeClassification.js";
import TtdMergeBranch from "./TtdMergeBranch.js";
import TtdMergeFootprint from "./TtdMergeFootprint.js";
import { TTD_MERGE_INSPECTION_DOMAINS, } from "./TtdMergeInspectionDomain.js";
import TtdMergeLoweringWitness from "./TtdMergeLoweringWitness.js";
import TtdMergeObstructionWitness from "./TtdMergeObstructionWitness.js";
import TtdMergePolicyRequirement from "./TtdMergePolicyRequirement.js";
import { freezeSortedRecord, freezeSortedTexts, requireStringRecord, } from "./TtdMergeValidation.js";
export const TTD_MERGE_INSPECTION_PROTOCOL_VERSION = 'ttd-merge-inspection/v1';
function requireDomain(domain) {
    if (!TTD_MERGE_INSPECTION_DOMAINS.includes(domain)) {
        throw new WarpError('merge inspection domain is invalid', 'E_TTD_MERGE_INSPECTION_INVALID');
    }
    return domain;
}
function requireBranch(item) {
    if (!(item instanceof TtdMergeBranch)) {
        throw new WarpError('merge inspection branches require TtdMergeBranch instances', 'E_TTD_MERGE_INSPECTION_INVALID');
    }
    return item;
}
function requireFootprint(item) {
    if (!(item instanceof TtdMergeFootprint)) {
        throw new WarpError('merge inspection footprints require TtdMergeFootprint instances', 'E_TTD_MERGE_INSPECTION_INVALID');
    }
    return item;
}
function requireObstruction(item) {
    if (!(item instanceof TtdMergeObstructionWitness)) {
        throw new WarpError('merge inspection obstructions require witness instances', 'E_TTD_MERGE_INSPECTION_INVALID');
    }
    return item;
}
function requireLowering(item) {
    if (!(item instanceof TtdMergeLoweringWitness)) {
        throw new WarpError('merge inspection lowerings require witness instances', 'E_TTD_MERGE_INSPECTION_INVALID');
    }
    return item;
}
function requirePolicy(item) {
    if (!(item instanceof TtdMergePolicyRequirement)) {
        throw new WarpError('merge inspection policies require policy instances', 'E_TTD_MERGE_INSPECTION_INVALID');
    }
    return item;
}
function requireClassification(classification) {
    if (!(classification instanceof MergeClassification)) {
        throw new WarpError('merge inspection classification is invalid', 'E_TTD_MERGE_INSPECTION_INVALID');
    }
    return classification;
}
export default class TtdMergeInspection {
    protocolVersion = TTD_MERGE_INSPECTION_PROTOCOL_VERSION;
    domain;
    sharedPrecursor;
    branches;
    footprints;
    overlapKeys;
    candidateCanonicalJoin;
    obstructionWitnesses;
    loweringWitnesses;
    policyRequirements;
    classification;
    constructor(fields) {
        this.domain = requireDomain(fields.domain);
        this.sharedPrecursor = requireStringRecord(fields.sharedPrecursor, 'sharedPrecursor');
        this.branches = Object.freeze(fields.branches.map(requireBranch));
        this.footprints = Object.freeze(fields.footprints.map(requireFootprint));
        this.overlapKeys = freezeSortedTexts(fields.overlapKeys, 'overlapKeys');
        this.candidateCanonicalJoin = fields.candidateCanonicalJoin === null
            ? null
            : freezeSortedRecord(fields.candidateCanonicalJoin);
        this.obstructionWitnesses = Object.freeze(fields.obstructionWitnesses.map(requireObstruction));
        this.loweringWitnesses = Object.freeze(fields.loweringWitnesses.map(requireLowering));
        this.policyRequirements = Object.freeze(fields.policyRequirements.map(requirePolicy));
        this.classification = requireClassification(fields.classification);
        Object.freeze(this);
    }
}
