/*!
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License.
 */
import { LocalDeltaConnectionServer } from "@fluidframework/server-local-server";
import { MultiDocumentServiceFactory } from "@fluidframework/driver-utils";
import { LocalDocumentServiceFactory, LocalSessionStorageDbFactory } from "@fluidframework/local-driver";
import { OdspDocumentServiceFactory } from "@fluidframework/odsp-driver";
import { RouterliciousDocumentServiceFactory } from "@fluidframework/routerlicious-driver";
import { getRandomName } from "@fluidframework/server-services-client";
import { InsecureTokenProvider } from "@fluidframework/test-runtime-utils";
import { v4 as uuid } from "uuid";
export const deltaConns = new Map();
export function getDocumentServiceFactory(documentId, options) {
    var _a;
    const deltaConn = (_a = deltaConns.get(documentId)) !== null && _a !== void 0 ? _a : LocalDeltaConnectionServer.create(new LocalSessionStorageDbFactory(documentId));
    deltaConns.set(documentId, deltaConn);
    const getUser = () => ({
        id: uuid(),
        name: getRandomName(),
    });
    let routerliciousTokenProvider;
    // tokenprovider and routerlicious document service will not be called for local and spo server.
    if (options.mode === "tinylicious") {
        routerliciousTokenProvider = new InsecureTokenProvider("12345", getUser());
    }
    else {
        routerliciousTokenProvider = new InsecureTokenProvider(options.tenantSecret, getUser());
    }
    return MultiDocumentServiceFactory.create([
        new LocalDocumentServiceFactory(deltaConn),
        // TODO: web socket token
        new OdspDocumentServiceFactory(async () => options.mode === "spo" || options.mode === "spo-df" ? options.odspAccessToken : undefined, async () => options.mode === "spo" || options.mode === "spo-df" ? options.pushAccessToken : undefined),
        new RouterliciousDocumentServiceFactory(routerliciousTokenProvider),
    ]);
}
//# sourceMappingURL=multiDocumentServiceFactory.js.map