/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
var _a;
import { createSharedObjectKind } from "@fluidframework/shared-object-base/internal";
import { pkgVersion } from "./packageVersion.js";
import { SharedTree as SharedTreeImpl } from "./shared-tree/index.js";
/**
 * A channel factory that creates an {@link ITree}.
 */
export class TreeFactory {
    constructor(options) {
        this.options = options;
        this.type = TreeFactory.Type;
        this.attributes = TreeFactory.attributes;
    }
    async load(runtime, id, services, channelAttributes) {
        const tree = new SharedTreeImpl(id, runtime, channelAttributes, this.options);
        await tree.load(services);
        return tree;
    }
    create(runtime, id) {
        const tree = new SharedTreeImpl(id, runtime, this.attributes, this.options);
        tree.initializeLocal();
        return tree;
    }
}
_a = TreeFactory;
TreeFactory.Type = "https://graph.microsoft.com/types/tree";
TreeFactory.attributes = {
    type: _a.Type,
    snapshotFormatVersion: "0.0.0",
    packageVersion: pkgVersion,
};
/**
 * SharedTree is a hierarchical data structure for collaboratively editing strongly typed JSON-like trees
 * of objects, arrays, and other data types.
 * @public
 */
export const SharedTree = configuredSharedTree({});
/**
 * {@link SharedTree} but allowing a non-default configuration.
 * @remarks
 * This is useful for debugging and testing to opt into extra validation or see if opting out of some optimizations fixes an issue.
 * @example
 * ```typescript
 * import {
 * 	ForestType,
 * 	TreeCompressionStrategy,
 * 	configuredSharedTree,
 * 	typeboxValidator,
 * 	// eslint-disable-next-line import/no-internal-modules
 * } from "@fluidframework/tree/internal";
 * const SharedTree = configuredSharedTree({
 * 	forest: ForestType.Reference,
 * 	jsonValidator: typeboxValidator,
 * 	treeEncodeType: TreeCompressionStrategy.Uncompressed,
 * });
 * ```
 * @privateRemarks
 * TODO:
 * Expose Ajv validator for better error message quality somehow.
 * Maybe as part of a test utils or dev-tool package?
 * @internal
 */
export function configuredSharedTree(options) {
    class ConfiguredFactory extends TreeFactory {
        constructor() {
            super(options);
        }
    }
    return createSharedObjectKind(ConfiguredFactory);
}
//# sourceMappingURL=treeFactory.js.map