import QueryError from "../../errors/QueryError.js";
import Optic from "./Optic.js";
const NODE_PROPERTY_OPTIC_KIND = 'node-property';
export default class NodePropertyOptic {
    _optic;
    _locator;
    constructor(options) {
        this._optic = validateNodePropertyOptic(options.optic);
        this._locator = options.locator;
        Object.freeze(this);
    }
    toOptic() {
        return this._optic;
    }
    async read() {
        return await this._locator.readNodeProperty(this._optic);
    }
}
function validateNodePropertyOptic(optic) {
    if (!(optic instanceof Optic) || optic.target.opticKind !== NODE_PROPERTY_OPTIC_KIND) {
        throwNodePropertyOpticError('optic', 'invalid-optic');
    }
    return optic;
}
function throwNodePropertyOpticError(field, reason) {
    throw new QueryError('Node property optic is invalid.', {
        code: 'E_NODE_PROPERTY_OPTIC',
        context: { field, reason },
    });
}
