import WarpError from "../errors/WarpError.js";
/** Payload identity for a git-warp read result feeding a reading envelope. */
export default class GitWarpReadingEnvelopePayloadFact {
    payloadKind;
    payloadDigest;
    stateHash;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.payloadKind = requireNonEmptyString(checkedFields.payloadKind, 'payloadKind');
        this.payloadDigest = requireNonEmptyString(checkedFields.payloadDigest, 'payloadDigest');
        this.stateHash = optionalNonEmptyString(checkedFields.stateHash, 'stateHash');
        Object.freeze(this);
    }
    /** Returns true when the payload carries a materialized state hash. */
    hasStateHash() {
        return this.stateHash !== undefined;
    }
}
/** Validates the payload-fact constructor envelope. */
function requireFields(value) {
    if (value === null || value === undefined) {
        throw new WarpError('GitWarpReadingEnvelopePayloadFact fields must be provided', '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;
}
/** Validates an optional non-empty string. */
function optionalNonEmptyString(value, name) {
    if (value === undefined) {
        return undefined;
    }
    return requireNonEmptyString(value, name);
}
