/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import type { SchemaAndPolicy, TreeFieldStoredSchema, TreeTypeSet } from "../core/index.js";
import { type FlexTreeContext, type FlexTreeHydratedContextMinimal, type FlexibleFieldContent, type FlexibleNodeContent, type FlexTreeNode, type DetachedRootsLocation } from "../feature-libraries/index.js";
import { type ImplicitFieldSchema } from "./fieldSchema.js";
import { type InsertableContent } from "./unhydratedFlexTreeFromInsertable.js";
import { type ImplicitAllowedTypes } from "./core/index.js";
/**
 * Prepare content from a user for insertion into a tree.
 * @remarks
 * This validates and converts the input, and if necessary invokes {@link prepareContentForHydration}.
 *
 * The next edit made to `destinationContext`'s forest must be the creation of a detached field containing this content,
 * (Triggering {@link ForestEvents.afterRootFieldCreated}) otherwise hydration will break.
 */
export declare function prepareForInsertion<TIn extends InsertableContent | undefined>(data: TIn, schema: ImplicitFieldSchema, destinationContext: FlexTreeContext, destinationSchema: TreeFieldStoredSchema): TIn extends undefined ? undefined : FlexibleNodeContent;
/**
 * {@link prepareForInsertion} but batched for array content.
 * @remarks
 * This is for inserting items into an array, not a inserting a {@link TreeArrayNode} (that would use {@link prepareForInsertion}).
 *
 * The next edits made to `destinationContext`'s forest must be the creation of a detached field.
 * One edit for each item in `data`, in order.
 *
 * @privateRemarks
 * This has to be done as a single operation for all items in data
 * (as opposed to mapping {@link prepareForInsertion} over the array)
 * due to how the eventing in prepareContentForHydration works.
 */
export declare function prepareArrayContentForInsertion(data: readonly InsertableContent[], schema: ImplicitAllowedTypes, destinationContext: FlexTreeContext, destinationSchema: TreeTypeSet): FlexibleFieldContent;
export interface PreparedContent {
    /**
     * New content which to be attached. Rooted in detached fields.
     * @remarks
     * When destination is a hydrated context, this will contain hydrated flex tree nodes.
     * The corresponding TreeNodes will not yet be hydrated, and some subtrees may be in separate detached fields.
     *
     * TODO: Eventually, this should be a single detached field, not an array of nodes each in their own detached field.
     */
    readonly toAttach?: readonly FlexTreeNode[];
    /**
     * Location of toAttach.
     * @remarks
     * This is redundant with `toAttach.key` but in a different format/type.
     * Only provided for hydrated destinations.
     */
    readonly rootsLocations?: DetachedRootsLocation;
    /**
     * Finalizes the prepared content. Moves in missing subtrees from detached fields, and hydrates TreeNodes as needed.
     *
     * @param attached - The nodes that were attached to the tree.
     *
     * @remarks
     * Call this exactly once, after `toAttach` has been attached to its final location.
     * There must be no app facing events between creation of this `PreparedContent` and its finalization since during this time TreeNodes may be in an invalid state (inner node hydrated, but TreeNode not).
     *
     * The implementation of this must not assume the context provided to `prepareForInsertion*` is still valid.
     */
    readonly finalize: (attached: readonly FlexTreeNode[]) => void;
}
/**
 * This exists to handle the required root initialize case where the flex tree nodes get invalidated by a schema change and thus new node instances need to be provided.
 */
export interface PreparedContentInitialize extends PreparedContent {
    /**
     * {@inheritDoc PreparedContent.rootIds}
     */
    readonly rootsLocations: DetachedRootsLocation;
}
/**
 * This exists to handle the required root initialize case where the flex tree nodes get invalidated by a schema change and thus new node instances need to be provided.
 */
export interface PreparedContentRegular extends PreparedContent {
    /**
     * {@inheritDoc PreparedContent.toAttach}
     */
    readonly toAttach: readonly FlexTreeNode[];
    /**
     * {@link PreparedContent.finalize} but without `attached` parameter: assumes `toAttach` is the same is still valid and uses that.
     */
    readonly finalize: () => void;
}
/**
 * Split out from {@link prepareForInsertion} as to allow use without a context.
 *
 * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.
 * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.
 *
 * @remarks
 * Adding this entry point is a workaround for initialize not currently having a context.
 */
export declare function prepareForInsertionContextless<TIn extends InsertableContent | undefined>(data: TIn, schema: ImplicitFieldSchema, schemaAndPolicy: SchemaAndPolicy, hydratedData: FlexTreeHydratedContextMinimal, destinationSchema: TreeFieldStoredSchema): PreparedContentInitialize;
//# sourceMappingURL=prepareForInsertion.d.ts.map