import WarpError from "../errors/WarpError.js";
/** One ordered git-warp patch reference inside a witnessed suffix source fact. */
export default class GitWarpWitnessedSuffixPatchFact {
    writerId;
    patchSha;
    lamport;
    operationCount;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.writerId = requireNonEmptyString(checkedFields.writerId, 'writerId');
        this.patchSha = requireNonEmptyString(checkedFields.patchSha, 'patchSha');
        this.lamport = requireNonNegativeInteger(checkedFields.lamport, 'lamport');
        this.operationCount = requireNonNegativeInteger(checkedFields.operationCount, 'operationCount');
        Object.freeze(this);
    }
}
/** Validates the patch-fact constructor envelope. */
function requireFields(value) {
    if (value === null || value === undefined) {
        throw new WarpError('GitWarpWitnessedSuffixPatchFact 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 a non-negative integer. */
function requireNonNegativeInteger(value, name) {
    if (!Number.isInteger(value) || value < 0) {
        throw new WarpError(`${name} must be a non-negative integer`, 'E_VALIDATION');
    }
    return value;
}
