"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.rawObjectErrorMessage = exports.createRawObjectNode = exports.nodeContent = void 0;
const util_1 = require("../../util");
const editableTreeTypes_1 = require("./editableTreeTypes");
/**
 * Used to acquire the content of a raw object node.
 */
exports.nodeContent = Symbol();
/**
 * Creates a node that falsely pretends to satisfy the given schema while wrapping the given node content.
 * Retrieve the node content via {@link nodeContent}.
 *
 * @remarks This is useful for creating "raw" nodes: nodes which capture data about a pending insertion but are not yet inserted.
 * These raw nodes can be then used on the right-hand side of an assignment (via `=`) to the tree.
 * However, their properties and methods should not be inspected (other than `schema` and `type`) since they are not implemented; they will error.
 *
 * @privateRemarks TODO: Generate these from schema, and use them to support `=`.
 */
function createRawObjectNode(schema, content) {
    const node = new RawObjectNode(schema, content);
    for (const [key] of schema.objectNodeFields) {
        Object.defineProperty(node, key, {
            get: () => rawObjectNodeError(),
            set: () => rawObjectNodeError(),
            enumerable: true,
        });
        Object.defineProperty(node, `boxed${(0, util_1.capitalize)(key)}`, {
            get: () => rawObjectNodeError(),
            set: () => rawObjectNodeError(),
            enumerable: false,
        });
    }
    return node;
}
exports.createRawObjectNode = createRawObjectNode;
class RawObjectNode {
    constructor(schema, content) {
        this.schema = schema;
        this[exports.nodeContent] = content;
    }
    get type() {
        return this.schema.name;
    }
    get context() {
        return rawObjectNodeError();
    }
    get parentField() {
        return rawObjectNodeError();
    }
    tryGetField(key) {
        return rawObjectNodeError();
    }
    [editableTreeTypes_1.boxedIterator]() {
        return rawObjectNodeError();
    }
    on(eventName, listener) {
        return rawObjectNodeError();
    }
    is(schema) {
        return rawObjectNodeError();
    }
    treeStatus() {
        return rawObjectNodeError();
    }
    get localNodeKey() {
        return rawObjectNodeError();
    }
}
function rawObjectNodeError() {
    throw new Error(exports.rawObjectErrorMessage);
}
exports.rawObjectErrorMessage = "Newly created node must be inserted into the tree before being queried";
//# sourceMappingURL=rawObjectNode.js.map