/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { TreeNodeSchemaIdentifier } from "../core";
import { Assume, RestrictiveReadonlyRecord } from "../util";
import { SchemaLibraryData, SchemaLintConfiguration, AllowedTypes, TreeNodeSchema, TreeFieldSchema, TreeSchema, FlexList, Unenforced, Any, MapFieldSchema, SchemaCollection, ObjectNodeSchema, MapNodeSchema, FieldNodeSchema } from "./typed-schema";
import { FieldKind } from "./modular-schema";
/**
 * Configuration for a SchemaBuilder.
 * @alpha
 */
export interface SchemaBuilderOptions<TScope extends string = string> {
    /**
     * Prefix appended to the identifiers of all {@link TreeNodeSchema} produced by this builder.
     * Use of [Reverse domain name notation](https://en.wikipedia.org/wiki/Reverse_domain_name_notation) or a UUIDv4 is recommended to avoid collisions.
     */
    scope: TScope;
    /**
     * Name used to refer to this builder in error messages.
     * Has no impact on the actual generated schema.
     * Defaults to scope.
     */
    name?: string;
    /**
     * Optional configuration for "linting".
     * See {@link SchemaLintConfiguration}. Currently defaults to enabling all lints.
     */
    lint?: Partial<SchemaLintConfiguration>;
    /**
     * Libraries to include in this one.
     *
     * @remarks
     * Unlike adding of individual schema, adding of libraries is idempotent.
     * If a single library is added multiple times (even indirectly via libraries it was added into),
     * only a single copy will be included, so they will not conflict.
     * This allows adding any library this one depends on without risk of conflicts for users of this library.
     * Contents within the added libraries can still conflict however.
     * Such errors will be reported when finalizing this builder into a library or document schema.
     */
    libraries?: SchemaLibrary[];
}
/**
 * Builds schema libraries, and the schema within them.
 * @alpha
 *
 * @privateRemarks
 * This class does not directly depend on any specific field kinds,
 * or bake in any defaults that might have compatibility implications.
 * All use of such implicit defaults is done by subclasses, which thus get versioning implications.
 */
export declare class SchemaBuilderBase<TScope extends string, TDefaultKind extends FieldKind, TName extends number | string = string> {
    private readonly defaultKind;
    private readonly lintConfiguration;
    private readonly libraries;
    private finalized;
    private readonly treeNodeSchema;
    private readonly adapters;
    /**
     * Prefix appended to the identifiers of all {@link TreeNodeSchema} produced by this builder.
     */
    readonly scope: TScope;
    /**
     * Used in error messages to identify content produced by this builder.
     */
    readonly name: string;
    /**
     * @param defaultKind - The default field kind to use when inferring a {@link TreeFieldSchema} from {@link ImplicitAllowedTypes}.
     */
    constructor(defaultKind: TDefaultKind, options: SchemaBuilderOptions<TScope>);
    protected scoped<Name extends TName>(name: Name): TreeNodeSchemaIdentifier<`${TScope}.${Name}`>;
    /**
     * Adds more libraries to this one.
     *
     * Unlike adding of individual schema, adding of libraries is idempotent.
     * If a single library is added multiple times (even indirectly via libraries it was added into),
     * only a single copy will be included, so they will not conflict.
     * This allows adding any library this one depends on without risk of conflicts for users of this library.
     * Contents within the added libraries can still conflict however.
     * Such errors will be reported when finalizing this builder into a library of document schema.
     */
    private addLibraries;
    protected addNodeSchema<T extends TreeNodeSchema>(schema: T): void;
    private finalizeCommon;
    /**
     * Produce SchemaLibraries which capture the content added to this builder, as well as any additional SchemaLibraries that were added to it.
     * May only be called once after adding content to builder is complete.
     */
    intoLibrary(): SchemaLibrary;
    /**
     * Produce a TreeSchema which captures the content added to this builder, any additional SchemaLibraries that were added to it and a root field.
     * Can be used with schematize to provide schema aware access to document content.
     *
     * @remarks
     * May only be called once after adding content to builder is complete.
     */
    intoSchema<const TSchema extends ImplicitFieldSchema>(root: TSchema): TreeSchema<NormalizeField<TSchema, TDefaultKind>>;
    /**
     * Define (and add to this library) a {@link ObjectNodeSchema}.
     *
     * The name must be unique among all TreeNodeSchema in the the document schema.
     */
    object<const Name extends TName, const T extends RestrictiveReadonlyRecord<string, ImplicitFieldSchema>>(name: Name, t: T): ObjectNodeSchema<`${TScope}.${Name}`, {
        [key in keyof T]: NormalizeField<T[key], TDefaultKind>;
    }>;
    /**
     * Same as `object` but with less type safety and works for recursive objects.
     * Reduced type safety is a side effect of a workaround for a TypeScript limitation.
     *
     * See {@link Unenforced} for details.
     *
     * TODO: Make this work with ImplicitFieldSchema.
     */
    objectRecursive<const Name extends TName, const T extends Unenforced<RestrictiveReadonlyRecord<string, ImplicitFieldSchema>>>(name: Name, t: T): ObjectNodeSchema<`${TScope}.${Name}`, T>;
    /**
     * Define (and add to this library) a {@link MapNodeSchema}.
     */
    map<Name extends TName, const T extends MapFieldSchema>(name: Name, fieldSchema: T): MapNodeSchema<`${TScope}.${Name}`, T>;
    /**
     * Same as `map` but with less type safety and works for recursive objects.
     * Reduced type safety is a side effect of a workaround for a TypeScript limitation.
     *
     * See {@link Unenforced} for details.
     *
     * TODO: Make this work with ImplicitFieldSchema.
     */
    mapRecursive<Name extends TName, const T extends Unenforced<MapFieldSchema>>(name: Name, t: T): MapNodeSchema<`${TScope}.${Name}`, T>;
    /**
     * Define (and add to this library) a {@link FieldNodeSchema}.
     *
     * The name must be unique among all TreeNodeSchema in the the document schema.
     *
     * @privateRemarks
     * TODO: Write and link document outlining field vs node data model and the separation of concerns related to that.
     * TODO: Maybe find a better name for this.
     */
    fieldNode<Name extends TName, const T extends ImplicitFieldSchema>(name: Name, fieldSchema: T): FieldNodeSchema<`${TScope}.${Name}`, NormalizeField<T, TDefaultKind>>;
    /**
     * Same as `fieldNode` but with less type safety and works for recursive objects.
     * Reduced type safety is a side effect of a workaround for a TypeScript limitation.
     *
     * See {@link Unenforced} for details.
     *
     * TODO: Make this work with ImplicitFieldSchema.
     */
    fieldNodeRecursive<Name extends TName, const T extends Unenforced<ImplicitFieldSchema>>(name: Name, t: T): FieldNodeSchema<`${TScope}.${Name}`, T>;
    /**
     * Define a {@link TreeFieldSchema}.
     *
     * @param kind - The [kind](https://en.wikipedia.org/wiki/Kind_(type_theory)) of this field.
     * Determine the multiplicity, viewing and editing APIs as well as the merge resolution policy.
     * @param allowedTypes - What types of children are allowed in this field.
     * @returns a {@link TreeFieldSchema} which can be used as a object field (see {@link SchemaBuilderBase.object}),
     * a map field (see {@link SchemaBuilderBase.map}), a field node (see {@link SchemaBuilderBase.fieldNode}) or the root field (see {@link SchemaBuilderBase.intoSchema}).
     *
     * @privateRemarks
     * TODO:
     * If a solution to TreeFieldSchema not being able to have extends clauses gets found,
     * consider just having users do `new TreeFieldSchema` instead?
     */
    static field<Kind extends FieldKind, T extends ImplicitAllowedTypes>(kind: Kind, allowedTypes: T): TreeFieldSchema<Kind, NormalizeAllowedTypes<T>>;
    /**
     * Define a schema for a field.
     * Same as {@link SchemaBuilderBase.field} but is less type safe and supports recursive types.
     * This API is less safe to work around a [limitation of TypeScript](https://github.com/microsoft/TypeScript/issues/55758).
     *
     * T must extends `AllowedTypes`: This cannot be enforced via TypeScript since such an "extends" clauses cause recursive types to error with:
     * "'theSchema' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer."
     *
     * TODO: Try and find a way to provide a more specific type without triggering the above error.
     */
    static fieldRecursive<Kind extends FieldKind, T extends FlexList<Unenforced<TreeNodeSchema>>>(kind: Kind, ...allowedTypes: T): TreeFieldSchema<Kind, T>;
    /**
     * Normalizes an {@link ImplicitFieldSchema} into a {@link TreeFieldSchema} using this schema builder's `defaultKind`.
     */
    protected normalizeField<TSchema extends ImplicitFieldSchema>(schema: TSchema): NormalizeField<TSchema, TDefaultKind>;
}
/**
 * Schema information collected by a SchemaBuilder, including referenced libraries.
 * Can be aggregated into other libraries by adding to their builders.
 * @alpha
 */
export interface SchemaLibrary extends SchemaCollection {
    /**
     * Schema data aggregated from a collection of libraries by a SchemaBuilder.
     */
    readonly libraries: ReadonlySet<SchemaLibraryData>;
}
/**
 * Generalized version of AllowedTypes allowing for more concise expressions in some cases.
 * @alpha
 */
export type ImplicitAllowedTypes = AllowedTypes | TreeNodeSchema | Any;
/**
 * Normalizes an {@link ImplicitAllowedTypes} into  {@link AllowedTypes}.
 * @alpha
 */
export type NormalizeAllowedTypes<TSchema extends ImplicitAllowedTypes> = TSchema extends TreeNodeSchema ? readonly [TSchema] : TSchema extends Any ? readonly [Any] : TSchema;
/**
 * Normalizes an {@link ImplicitAllowedTypes} into  {@link AllowedTypes}.
 */
export declare function normalizeAllowedTypes<TSchema extends ImplicitAllowedTypes>(schema: TSchema): NormalizeAllowedTypes<TSchema>;
/**
 * Normalizes an {@link ImplicitFieldSchema} into a {@link TreeFieldSchema}.
 * @alpha
 */
export type NormalizeField<TSchema extends ImplicitFieldSchema, TDefault extends FieldKind> = TSchema extends TreeFieldSchema ? TSchema : TreeFieldSchema<TDefault, NormalizeAllowedTypes<Assume<TSchema, ImplicitAllowedTypes>>>;
/**
 * Normalizes an {@link ImplicitFieldSchema} into a {@link TreeFieldSchema}.
 */
export declare function normalizeField<TSchema extends ImplicitFieldSchema, TDefault extends FieldKind>(schema: TSchema, defaultKind: TDefault): NormalizeField<TSchema, TDefault>;
/**
 * Type that when combined with a default {@link FieldKind} can be normalized into a {@link TreeFieldSchema}.
 * @alpha
 */
export type ImplicitFieldSchema = TreeFieldSchema | ImplicitAllowedTypes;
//# sourceMappingURL=schemaBuilderBase.d.ts.map