import ProvenancePayload from "../services/provenance/ProvenancePayload.js";
import WarpError from "../errors/WarpError.js";
/** Replay-bearing hologram for lawful distributed suffix transport. */
export default class GitWarpSuffixTransformHologram {
    sourceFrontierRef;
    basisFrontierRef;
    targetFrontierRef;
    transportLawId;
    proofRef;
    payload;
    patchCount;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.sourceFrontierRef = requireNonEmptyString(checkedFields.sourceFrontierRef, 'sourceFrontierRef');
        this.basisFrontierRef = requireNonEmptyString(checkedFields.basisFrontierRef, 'basisFrontierRef');
        this.targetFrontierRef = requireNonEmptyString(checkedFields.targetFrontierRef, 'targetFrontierRef');
        this.transportLawId = requireNonEmptyString(checkedFields.transportLawId, 'transportLawId');
        this.proofRef = requireNonEmptyString(checkedFields.proofRef, 'proofRef');
        this.payload = requireNonEmptyPayload(checkedFields.payload);
        this.patchCount = this.payload.length;
        Object.freeze(this);
    }
    /** Deterministically materializes the target frontier from the local basis. */
    materializeFrom(basis) {
        return this.payload.replay(basis);
    }
}
function requireFields(value) {
    if (value === null || value === undefined) {
        throw new WarpError('GitWarpSuffixTransformHologram fields must be provided', 'E_VALIDATION');
    }
    return value;
}
function requireNonEmptyPayload(value) {
    if (!(value instanceof ProvenancePayload)) {
        throw new WarpError('payload must be a ProvenancePayload', 'E_VALIDATION');
    }
    if (value.length === 0) {
        throw new WarpError('suffix transform hologram payload must not be empty', 'E_VALIDATION');
    }
    return value;
}
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;
}
