import ImmutableBytes from "../snapshot/ImmutableBytes.js";
import WarpError from "../../errors/WarpError.js";
/** Verkle opening proof for one coordinate inside a cold wormhole segment. */
export default class ApertureOpeningProof {
    evaluatedTick;
    evaluatedNodeId;
    evaluatedValue;
    verkleProof;
    constructor(fields) {
        const checkedFields = requireFields(fields);
        this.evaluatedTick = requireNonNegativeInteger(checkedFields.evaluatedTick, 'evaluatedTick');
        this.evaluatedNodeId = requireNonEmptyString(checkedFields.evaluatedNodeId, 'evaluatedNodeId');
        this.evaluatedValue = requireBytes(checkedFields.evaluatedValue, 'evaluatedValue');
        this.verkleProof = requireNonEmptyBytes(checkedFields.verkleProof, 'verkleProof');
        Object.freeze(this);
    }
    evaluatedValueBytes() {
        return this.evaluatedValue.toUint8Array();
    }
    verkleProofBytes() {
        return this.verkleProof.toUint8Array();
    }
}
function requireFields(value) {
    if (value === null || value === undefined) {
        throw new WarpError('ApertureOpeningProof fields must be provided', 'E_VALIDATION');
    }
    return value;
}
function requireBytes(value, name) {
    if (!(value instanceof Uint8Array)) {
        throw new WarpError(`${name} must be a Uint8Array`, 'E_VALIDATION');
    }
    return new ImmutableBytes(value);
}
function requireNonEmptyBytes(value, name) {
    if (!(value instanceof Uint8Array) || value.length === 0) {
        throw new WarpError(`${name} must be a non-empty Uint8Array`, 'E_VALIDATION');
    }
    return new ImmutableBytes(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;
}
function requireNonNegativeInteger(value, name) {
    if (!Number.isInteger(value) || value < 0) {
        throw new WarpError(`${name} must be a non-negative integer`, 'E_VALIDATION');
    }
    return value;
}
