/**
 * Finsemble entry point for services and the service manager.
 */
import { RouterClient, RouterController } from "../routerClient";
import { getRouterConfig, getSystemStartupData, getManifestFromStartupData } from "./RouterConfig";
import { System } from "../../common/system";
import { Startup } from "./Startup";
import { Globals } from "../../common/Globals";
import { FinsembleDesktopAgent } from "../Interop/FinsembleDesktopAgent";
import uuidv4 from "uuid-random";
export class FSBLService {
    /**
     * Starts Finsemble for internal service and service manager windows
     */
    async startApp() {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        const systemStartupData = await getSystemStartupData();
        const finWindow = System.Window.getCurrent();
        const appName = (_c = (_a = finWindow.name) !== null && _a !== void 0 ? _a : (_b = document === null || document === void 0 ? void 0 : document.location) === null || _b === void 0 ? void 0 : _b.href) !== null && _c !== void 0 ? _c : "Unknown App";
        const windowName = (_f = (_d = finWindow.name) !== null && _d !== void 0 ? _d : (_e = document === null || document === void 0 ? void 0 : document.location) === null || _e === void 0 ? void 0 : _e.href) !== null && _f !== void 0 ? _f : `Unknown window-${uuidv4()}`;
        const webContentsName = (_g = finWindow.webContentsName) !== null && _g !== void 0 ? _g : windowName;
        /**
         * The system manifest is provided in the startup data. At early stages, this is available
         * at the root level. In later stages, a more complete manifest is available in customData.
         */
        const systemManifest = (_h = getManifestFromStartupData(systemStartupData)) !== null && _h !== void 0 ? _h : {};
        const routerConfig = getRouterConfig({
            windowName,
            systemManifest,
            isFSBLService: true,
        });
        await RouterController.start(routerConfig);
        const startup = Startup.getInstance();
        startup.setStartupData({
            windowName,
            webContentsName,
            authenticationToken: {
                signatureString: "",
                signatureStringType: "unauthenticated",
                meta: {
                    name: appName,
                    appId: appName,
                },
            },
        });
        // Made fdc3 available to services. This is temporary until services become invisible, singleton apps.
        Globals.fdc3 = new FinsembleDesktopAgent({
            routerClient: RouterClient,
            startup,
        });
        startup.setReady();
        // search for Logger.start() and client initialize calls in services and move them here
    }
    async stopApp() {
        RouterController.stop();
    }
}
//# sourceMappingURL=FSBLService.js.map