import ContinuumEvidencePosture from "./ContinuumEvidencePosture.js";
import ContinuumFamilyId from "./ContinuumFamilyId.js";
import ContinuumGeneratedFamilyInventoryEntry from "./ContinuumGeneratedFamilyInventoryEntry.js";
import GitWarpReadingEnvelopePayloadFact from "./GitWarpReadingEnvelopePayloadFact.js";
import WarpError from "../errors/WarpError.js";
const RUNTIME_BOUNDARY_FAMILY_ID = 'runtime-boundary-family';
/** Translated git-warp source facts for a future runtime-boundary reading envelope. */
export default class GitWarpReadingEnvelopeSourceFacts {
    family;
    evidencePosture;
    observerPlanId;
    observationRequestId;
    sourceRef;
    basisRef;
    payload;
    witnessRef;
    budgetStatus;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.family = requireRuntimeBoundaryFamily(checkedFields.family);
        this.evidencePosture = requireTranslatedPosture(checkedFields.evidencePosture);
        this.observerPlanId = requireNonEmptyString(checkedFields.observerPlanId, 'observerPlanId');
        this.observationRequestId = requireNonEmptyString(checkedFields.observationRequestId, 'observationRequestId');
        this.sourceRef = requireNonEmptyString(checkedFields.sourceRef, 'sourceRef');
        this.basisRef = requireNonEmptyString(checkedFields.basisRef, 'basisRef');
        this.payload = requirePayload(checkedFields.payload);
        this.witnessRef = requireNonEmptyString(checkedFields.witnessRef, 'witnessRef');
        this.budgetStatus = requireNonEmptyString(checkedFields.budgetStatus, 'budgetStatus');
        Object.freeze(this);
    }
    /** Returns true until runtime-boundary has a generated Wesley profile and fixture. */
    requiresGeneratedProfileBeforeProjection() {
        return !this.family.isProjectionReady();
    }
}
/** Validates the source-facts constructor envelope. */
function requireFields(value) {
    if (value === null || value === undefined) {
        throw new WarpError('GitWarpReadingEnvelopeSourceFacts fields must be provided', 'E_VALIDATION');
    }
    return value;
}
/** Requires the runtime-boundary inventory row. */
function requireRuntimeBoundaryFamily(value) {
    if (!(value instanceof ContinuumGeneratedFamilyInventoryEntry)) {
        throw new WarpError('family must be a ContinuumGeneratedFamilyInventoryEntry', 'E_VALIDATION');
    }
    if (!value.familyId.equals(new ContinuumFamilyId(RUNTIME_BOUNDARY_FAMILY_ID))) {
        throw new WarpError('reading envelope source facts require runtime-boundary-family', 'E_VALIDATION');
    }
    return value;
}
/** Requires translated git-warp evidence posture. */
function requireTranslatedPosture(value) {
    if (!(value instanceof ContinuumEvidencePosture)) {
        throw new WarpError('evidencePosture must be a ContinuumEvidencePosture', 'E_VALIDATION');
    }
    const posture = value;
    if (!posture.isTranslatedGitWarpEvidence()) {
        throw new WarpError('reading envelope source facts require translated git-warp evidence', 'E_VALIDATION');
    }
    return posture;
}
/** Validates a reading payload carrier. */
function requirePayload(value) {
    if (!(value instanceof GitWarpReadingEnvelopePayloadFact)) {
        throw new WarpError('payload must be a GitWarpReadingEnvelopePayloadFact', 'E_VALIDATION');
    }
    return value;
}
/** Validates a required non-empty string. */
function requireNonEmptyString(value, name) {
    if (typeof value !== 'string' || value.length === 0) {
        throw new WarpError(`${name} must be a non-empty string`, 'E_VALIDATION');
    }
    return value;
}
