"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.createLocalDataStoreContext = exports.createSummarizerNodeAndGetCreateFn = exports.createParentContext = void 0;
const internal_1 = require("@fluidframework/runtime-definitions/internal");
const internal_2 = require("@fluidframework/telemetry-utils/internal");
const internal_3 = require("@fluidframework/test-runtime-utils/internal");
const dataStoreContext_js_1 = require("../dataStoreContext.js");
const index_js_1 = require("../summary/index.js");
function createParentContext(logger = (0, internal_2.createChildLogger)(), clientDetailsOverrides, compatDetails) {
    const factory = {
        type: "store-type",
        get IFluidDataStoreFactory() {
            return factory;
        },
        instantiateDataStore: async (context) => {
            const mockDataStoreRuntime = new internal_3.MockFluidDataStoreRuntime();
            if (compatDetails !== undefined) {
                mockDataStoreRuntime.ILayerCompatDetails = compatDetails;
            }
            return mockDataStoreRuntime;
        },
    };
    const registry = {
        get IFluidDataStoreRegistry() {
            return registry;
        },
        get: async (pkg) => (pkg === "BOGUS" ? undefined : factory),
    };
    const clientDetails = {
        capabilities: { interactive: true },
        ...clientDetailsOverrides,
    };
    return {
        IFluidDataStoreRegistry: registry,
        baseLogger: logger,
        clientDetails,
        submitMessage: () => { },
        deltaManager: new internal_3.MockDeltaManager(),
        isReadOnly: () => !clientDetails.capabilities.interactive,
    };
}
exports.createParentContext = createParentContext;
function createSummarizerNodeAndGetCreateFn(dataStoreId) {
    const summarizerNode = (0, index_js_1.createRootSummarizerNodeWithGC)((0, internal_2.createChildLogger)(), (() => undefined), 0, 0);
    summarizerNode.startSummary(0, (0, internal_2.createChildLogger)(), 0);
    const createSummarizerNodeFn = (summarizeInternal, getGCDataFn) => summarizerNode.createChild(summarizeInternal, dataStoreId, { type: internal_1.CreateSummarizerNodeSource.Local }, undefined, getGCDataFn);
    return { summarizerNode, createSummarizerNodeFn };
}
exports.createSummarizerNodeAndGetCreateFn = createSummarizerNodeAndGetCreateFn;
const defaultCreateProps = {
    id: "dataStoreId",
    pkg: ["dataStorePkg"],
    storage: {},
    scope: {},
    snapshotTree: undefined,
    makeLocallyVisibleFn: () => { },
};
function createLocalDataStoreContext(props, compatDetails) {
    const localProps = {
        ...defaultCreateProps,
        ...props,
        parentContext: props.parentContext ?? createParentContext(undefined, undefined, compatDetails),
        createSummarizerNodeFn: props.createSummarizerNodeFn ??
            createSummarizerNodeAndGetCreateFn(props.id ?? defaultCreateProps.id)
                .createSummarizerNodeFn,
    };
    return new dataStoreContext_js_1.LocalFluidDataStoreContext(localProps);
}
exports.createLocalDataStoreContext = createLocalDataStoreContext;
//# sourceMappingURL=dataStoreCreationHelper.js.map