import OpticReadFailureSchemaError from "./OpticReadFailureSchemaError.js";
export default class OpticReadFailureContext {
    sourceContext;
    graphName;
    target;
    cause;
    includeReason;
    constructor(options) {
        if (options.graphName.length === 0) {
            throw new OpticReadFailureSchemaError('optic read failure context requires graphName');
        }
        this.sourceContext = Object.freeze({ ...options.sourceContext });
        this.graphName = options.graphName;
        this.target = options.target;
        this.cause = options.cause;
        this.includeReason = options.includeReason;
        Object.freeze(this);
    }
    toQueryErrorContext() {
        const context = {
            ...this.sourceContext,
            graphName: this.graphName,
            opticKind: this.target.opticKind,
            target: this.target.toContextValue(),
            cause: this.cause.value,
            recoveryHints: Object.freeze(this.cause.recoveryHints().map((hint) => hint.toContextValue())),
        };
        if (this.includeReason) {
            return this.freezeContext({ ...context, reason: this.cause.value });
        }
        return this.freezeContext(context);
    }
    freezeContext(context) {
        return Object.freeze(context);
    }
}
