/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { TreeValue } from "../core";
import { RestrictiveReadonlyRecord } from "../util";
import { FieldKind, FieldKinds, AllowedTypes, Any, FieldNodeSchema, TreeFieldSchema, InternalTypedSchemaTypes, LeafNodeSchema, MapNodeSchema, ObjectNodeSchema, TreeNodeSchema, TreeSchema } from "../feature-libraries";
/**
 * Data from which a {@link TreeObjectNode} can be built.
 */
export type InsertableTreeObjectNode<TSchema extends ObjectNodeSchema> = InsertableTreeObjectNodeFields<TSchema["objectNodeFieldsObject"]>;
/**
 * Helper for generating the properties of a InsertableTreeObjectNode.
 */
export type InsertableTreeObjectNodeFields<TFields extends RestrictiveReadonlyRecord<string, TreeFieldSchema>> = {
    readonly [key in keyof TFields]?: InsertableTreeField<TFields[key]>;
} & {
    readonly [key in keyof TFields as TFields[key]["kind"] extends typeof FieldKinds.optional ? never : key]-?: InsertableTreeField<TFields[key]>;
};
/**
 * Data from which a {@link TreeField} can be built.
 */
export type InsertableTreeField<TSchema extends TreeFieldSchema = TreeFieldSchema> = InsertableTreeFieldInner<TSchema["kind"], TSchema["allowedTypes"]>;
/**
 * Helper for implementing InsertableTreeField.
 */
export type InsertableTreeFieldInner<Kind extends FieldKind, TTypes extends AllowedTypes> = Kind extends typeof FieldKinds.sequence ? never : Kind extends typeof FieldKinds.required ? InsertableTreeNodeUnion<TTypes> : Kind extends typeof FieldKinds.optional ? InsertableTreeNodeUnion<TTypes> | undefined : unknown;
/**
 * Given multiple node schema types, return the corresponding object type union from which the node could be built.
 *
 * If the types are ambagious, use the schema's factory to construct a unhydrated node instance with the desired type.
 */
export type InsertableTreeNodeUnion<TTypes extends AllowedTypes> = TTypes extends readonly [Any] ? unknown : {
    [Index in keyof TTypes]: TTypes[Index] extends InternalTypedSchemaTypes.LazyItem<infer InnerType> ? InnerType extends TreeNodeSchema ? InsertableTypedNode<InnerType> : never : never;
}[number];
/**
 * Given a node's schema, return the corresponding object from which the node could be built.
 */
export type InsertableTypedNode<TSchema extends TreeNodeSchema> = TSchema extends LeafNodeSchema ? TreeValue<TSchema["info"]> : TSchema extends MapNodeSchema ? ReadonlyMap<string, InsertableTreeField<TSchema["info"]>> : TSchema extends FieldNodeSchema ? readonly InsertableTreeNodeUnion<TSchema["info"]["allowedTypes"]>[] : TSchema extends ObjectNodeSchema ? InsertableTreeObjectNode<TSchema> : unknown;
/**
 * Data which can be built into an entire tree matching the provided schema.
 */
export type InsertableTreeRoot<TSchema extends TreeSchema> = TSchema extends TreeSchema<infer TRootFieldSchema> ? InsertableTreeField<TRootFieldSchema> : never;
//# sourceMappingURL=insertable.d.ts.map