"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.typedSchemaData = exports.ApiMode = void 0;
const contextuallyTyped_1 = require("../contextuallyTyped");
const modular_schema_1 = require("../modular-schema");
const defaultSchema_1 = require("../defaultSchema");
/**
 * Different schema aware APIs that can be generated.
 * @alpha
 */
var ApiMode;
(function (ApiMode) {
    /**
     * Allow all forms accepted as ContextuallyTypedNodeData that align with the schema.
     * Types are optional.
     *
     * This also permits some cases which are ambiguous and thus would be rejected by `applyFieldTypesFromContext`.
     */
    ApiMode[ApiMode["Flexible"] = 0] = "Flexible";
    /**
     * Similar to what EditableTree uses.
     * No flexibility in representation.
     * Nodes are with primitives unwrapped to just the primitive.
     * Requires types on all node objects.
     *
     * TODO: fix ways this differs from editable tree:
     * - Does not do primary field inlining.
     * - Primitive node handling might not match.
     */
    ApiMode[ApiMode["Editable"] = 1] = "Editable";
    /**
     * Always use full node objects for everything.
     *
     * Fields are still shaped based on their multiplicity.
     */
    ApiMode[ApiMode["Wrapped"] = 2] = "Wrapped";
    /**
     * Simplified version of Flexible.
     *
     * Primitive values are always unwrapped.
     */
    ApiMode[ApiMode["Simple"] = 3] = "Simple";
})(ApiMode = exports.ApiMode || (exports.ApiMode = {}));
/**
 * Collects schema into a `TypedSchemaData` without losing type information.
 *
 * TODO:
 * 1. Extend this to support global fields.
 * 2. Extend this to better support use in libraries
 * which only have partial knowledge of what schema exist.
 * Currently unbounded polymorphism is not correct in that case.
 *
 *
 * @alpha
 */
function typedSchemaData(globalFieldSchema, ...t) {
    const treeSchemaObject = {};
    const allTypes = [];
    for (const schema of t) {
        Object.defineProperty(treeSchemaObject, schema.name, {
            enumerable: true,
            configurable: true,
            writable: false,
            value: schema,
        });
        allTypes.push(schema.name);
    }
    const schemaData = {
        policy: defaultSchema_1.defaultSchemaPolicy,
        globalFieldSchema: new Map(globalFieldSchema),
        treeSchema: new Map(t.map((schema) => [schema.name, schema])),
        treeSchemaObject: treeSchemaObject,
        allTypes: allTypes,
    };
    return schemaData;
}
exports.typedSchemaData = typedSchemaData;
//# sourceMappingURL=schemaAware.js.map