"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.configuredSharedTree = exports.SharedTree = exports.TreeFactory = void 0;
const internal_1 = require("@fluidframework/shared-object-base/internal");
const packageVersion_js_1 = require("./packageVersion.js");
const index_js_1 = require("./shared-tree/index.js");
/**
 * A channel factory that creates an {@link ITree}.
 */
class TreeFactory {
    constructor(options) {
        this.options = options;
        this.type = _a.Type;
        this.attributes = _a.attributes;
    }
    async load(runtime, id, services, channelAttributes) {
        const tree = new index_js_1.SharedTree(id, runtime, channelAttributes, this.options);
        await tree.load(services);
        return tree;
    }
    create(runtime, id) {
        const tree = new index_js_1.SharedTree(id, runtime, this.attributes, this.options);
        tree.initializeLocal();
        return tree;
    }
}
exports.TreeFactory = TreeFactory;
_a = TreeFactory;
TreeFactory.Type = "https://graph.microsoft.com/types/tree";
TreeFactory.attributes = {
    type: _a.Type,
    snapshotFormatVersion: "0.0.0",
    packageVersion: packageVersion_js_1.pkgVersion,
};
/**
 * SharedTree is a hierarchical data structure for collaboratively editing strongly typed JSON-like trees
 * of objects, arrays, and other data types.
 * @legacy
 * @alpha
 */
exports.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
 * This should be legacy, but has to be internal due to limitations of API tagging preventing it from being both alpha and alpha+legacy.
 * TODO:
 * Expose Ajv validator for better error message quality somehow.
 * Maybe as part of a test utils or dev-tool package?
 * @internal
 */
function configuredSharedTree(options) {
    class ConfiguredFactory extends TreeFactory {
        constructor() {
            super(options);
        }
    }
    return (0, internal_1.createSharedObjectKind)(ConfiguredFactory);
}
exports.configuredSharedTree = configuredSharedTree;
//# sourceMappingURL=treeFactory.js.map