"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchemaBuilder = void 0;
const index_js_1 = require("../feature-libraries/index.js");
const leafDomain_js_1 = require("./leafDomain.js");
/**
 * Builds schema libraries, and the schema within them.
 *
 * @remarks
 * Fields, when inferred from {@link FlexImplicitFieldSchema}, default to the `Required` {@link FlexFieldKind} (except for in Maps, which default to `Optional`).
 * Implicitly includes `leaf` schema library by default.
 *
 * This type has some built in defaults which impact compatibility.
 * This includes which {@link FlexFieldKind}s it uses.
 * To ensure that these defaults can be updated without compatibility issues,
 * this class is versioned: the number in its name indicates its compatibility,
 * and if its defaults are changed to ones that would not be compatible with a version of the application using the previous versions,
 * this number will be updated to make it impossible for an app to implicitly do a compatibility breaking change by updating this package.
 * Major package version updates are allowed to break API compatibility, but must not break content compatibility unless a corresponding code change is made in the app to opt in.
 *
 * @privateRemarks
 * TODO: Maybe rename to DefaultSchemaBuilder1 because of the versioning implications above.
 * Same applies to SchemaBuilder.
 * TODO: figure out a way to link `leaf` above without breaking API Extractor.
 * @sealed
 * @deprecated Users of this class should either use {@link SchemaBuilderBase} and explicitly work with {@link FlexFieldSchema}, or use SchemaFactory and work at its higher level of abstraction.
 */
class SchemaBuilder extends index_js_1.SchemaBuilderBase {
    constructor(options) {
        super(index_js_1.FieldKinds.required, {
            ...options,
            libraries: [...(options.libraries ?? []), leafDomain_js_1.leaf.library],
        });
        /**
         * Define a schema for an {@link FieldKinds.optional|optional field}.
         * @remarks
         * Shorthand for passing `FieldKinds.optional` to {@link FlexFieldSchema.create}.
         *
         * Since this creates a {@link FlexFieldSchema} (and not a {@link FlexTreeNodeSchema}), the resulting schema is structurally typed, and not impacted by the {@link SchemaBuilderBase.scope}:
         * therefore this method is the same as the static version.
         */
        this.optional = SchemaBuilder.optional;
        /**
         * Define a schema for a {@link FieldKinds.required|required field}.
         * @remarks
         * Shorthand for passing `FieldKinds.required` to {@link FlexFieldSchema.create}.
         * Note that `FieldKinds.required` is the current default field kind, so APIs accepting {@link FlexImplicitFieldSchema}
         * can be passed the `allowedTypes` and will implicitly wrap it up in a {@link FieldKinds.required|required field}.
         *
         * Since this creates a {@link FlexFieldSchema} (and not a {@link FlexTreeNodeSchema}), the resulting schema is structurally typed, and not impacted by the {@link SchemaBuilderBase.scope}:
         * therefore this method is the same as the static version.
         */
        this.required = SchemaBuilder.required;
        /**
         * Define a schema for a {@link FieldKinds.sequence|sequence field}.
         * @remarks
         * Shorthand for passing `FieldKinds.sequence` to {@link FlexFieldSchema.create}.
         *
         * Since this creates a {@link FlexFieldSchema} (and not a {@link FlexTreeNodeSchema}), the resulting schema is structurally typed, and not impacted by the {@link SchemaBuilderBase.scope}:
         * therefore this method is the same as the static version.
         */
        this.sequence = SchemaBuilder.sequence;
        /**
         * Define a schema for a {@link FieldKinds.identifier|identifier field}.
         * @remarks
         * Shorthand for passing `FieldKinds.identifier` to {@link TreeFieldSchema.create}.
         *
         * Since this creates a {@link TreeFieldSchema} (and not a {@link FlexTreeNodeSchema}), the resulting schema is structurally typed, and not impacted by the {@link SchemaBuilderBase.scope}:
         * therefore this method is the same as the static version.
         */
        this.identifier = SchemaBuilder.identifier;
    }
    objectRecursive(name, t) {
        return this.object(name, t);
    }
    /**
     * Define (and add to this library) a {@link FlexFieldNodeSchema} for a {@link Sequence}.
     *
     * The name must be unique among all TreeNodeSchema in the the document schema.
     */
    list(name, allowedTypes) {
        const schema = index_js_1.FlexFieldNodeSchema.create(this, this.scoped(name), this.sequence(allowedTypes));
        this.addNodeSchema(schema);
        return schema;
    }
}
exports.SchemaBuilder = SchemaBuilder;
/**
 * Define a schema for an {@link FieldKinds.optional|optional field}.
 * @remarks
 * Shorthand for passing `FieldKinds.optional` to {@link FlexFieldSchema.create}.
 *
 * This method is also available as an instance method on {@link SchemaBuilder}.
 */
SchemaBuilder.optional = fieldHelper(index_js_1.FieldKinds.optional);
/**
 * Define a schema for a {@link FieldKinds.required|required field}.
 * @remarks
 * Shorthand for passing `FieldKinds.required` to {@link FlexFieldSchema.create}.
 *
 * This method is also available as an instance method on {@link SchemaBuilder}.
 */
SchemaBuilder.required = fieldHelper(index_js_1.FieldKinds.required);
/**
 * Define a schema for a {@link FieldKinds.sequence|sequence field}.
 * @remarks
 * Shorthand for passing `FieldKinds.sequence` to {@link FlexFieldSchema.create}.
 *
 * This method is also available as an instance method on {@link SchemaBuilder}
 */
SchemaBuilder.sequence = fieldHelper(index_js_1.FieldKinds.sequence);
/**
 * Define a schema for an {@link FieldKinds.identifier|identifier field}.
 * @remarks
 * Shorthand for passing `FieldKinds.identifier` to {@link TreeFieldSchema.create}.
 *
 * This method is also available as an instance method on {@link SchemaBuilder}
 */
SchemaBuilder.identifier = fieldHelper(index_js_1.FieldKinds.identifier);
/**
 * Returns a wrapper around SchemaBuilder.field for a specific FieldKind.
 */
function fieldHelper(kind) {
    return (allowedTypes) => SchemaBuilder.field(kind, allowedTypes);
}
//# sourceMappingURL=schemaBuilder.js.map