import QueryError from "../../errors/QueryError.js";
import Optic from "./Optic.js";
const NEIGHBORHOOD_OPTIC_KIND = 'neighborhood';
export default class NeighborhoodOptic {
    _optic;
    _locator;
    constructor(options) {
        this._optic = validateNeighborhoodOptic(options.optic);
        this._locator = options.locator;
        Object.freeze(this);
    }
    toOptic() {
        return this._optic;
    }
    async read(options = {}) {
        return await this._locator.readNeighborhood(this._optic, options);
    }
}
function validateNeighborhoodOptic(optic) {
    if (!(optic instanceof Optic) || optic.target.opticKind !== NEIGHBORHOOD_OPTIC_KIND) {
        throwNeighborhoodOpticError('optic', 'invalid-optic');
    }
    return optic;
}
function throwNeighborhoodOpticError(field, reason) {
    throw new QueryError('Neighborhood optic is invalid.', {
        code: 'E_NEIGHBORHOOD_OPTIC',
        context: { field, reason },
    });
}
