"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BootstrapperForEnterpriseCommands = void 0;
require("reflect-metadata");
const codiac_common_1 = require("@codiac.io/codiac-common");
const client_1 = require("@codiac.io/codiac-messaging/dist/nats/client");
// import { NatsClient } from "./apis/nats/nats-client";
const relay_container_1 = require("./relay/relay-container");
const uilogic_1 = require("./uilogic");
const entities_1 = require("./ops/entities");
const relay_websocket_client_1 = require("./relay/wsclient/relay-websocket-client");
const lrp_watcher_predef_1 = require("./uilogic/lrp-watcher-predef");
const rootmap_ui_utils_1 = require("./uilogic/rootmap-ui-utils");
const INTERFACES_CLI_1 = require("./ops/INTERFACES_CLI");
const type_safety_utils_1 = require("./uilogic/type-safety-utils");
const bootstrapper_for_codiac_cli_1 = require("./bootstrapper-for-codiac-cli");
const bootstrapper_for_api_clients_1 = require("./bootstrapper-for-api-clients");
class BootstrapperForEnterpriseCommands {
    static bootstrap(ioc, cmd) {
        var _a, _b, _c;
        if (this.isBootstrapped == true) {
            return;
        }
        cmd.requiresProjectScope = false;
        bootstrapper_for_codiac_cli_1.BootstrapperForCodiacCli.bootstrap(ioc, cmd.config, cmd.requiresProjectScope);
        bootstrapper_for_api_clients_1.BootstrapperForApiClients.bootstrap(ioc, cmd);
        const apiClientKind = (_c = (_b = (_a = cmd.localConfig) === null || _a === void 0 ? void 0 : _a.apiClientKind) !== null && _b !== void 0 ? _b : cmd._cliCfg.apiClientKind) !== null && _c !== void 0 ? _c : entities_1.ApiClientKindEnum.nats;
        const useNats = Boolean(apiClientKind == entities_1.ApiClientKindEnum.nats);
        ioc.bind(uilogic_1.INTERFACES_CLI_ENTERPRISE.IContainerManager).toDynamicValue(ctx => {
            var _a, _b;
            let relayCtrSettings = {
                healthCheckUrl: useNats ? "nats://localhost:4222" : "http://localhost:5799/heartbeat-json",
                retryTimeout: undefined
            };
            let relayContainer = new relay_container_1.RelayContainer(ctx.container.get(INTERFACES_CLI_1.INTERFACES_CLI.IOutputStyler), ctx.container.get(entities_1.CliEnviro), ctx.container.get(codiac_common_1.INTERFACES.IBetterLogger), relayCtrSettings.healthCheckUrl, relayCtrSettings.retryTimeout, (_a = ctx.container.get(entities_1.ProjectEnviro)) === null || _a === void 0 ? void 0 : _a.projectRoot, type_safety_utils_1.TypeSafetyUtils.toBoolean((_b = ctx.container.get(entities_1.CliConfig)) === null || _b === void 0 ? void 0 : _b.localEntities));
            return relayContainer;
        });
        // ioc.bind<ExtendedRelayClient>(ExtendedRelayClient).toDynamicValue(ctx => {
        //   // let apiRootUrl: string | undefined;
        //   let relayAuthToken: string | undefined;
        //   let relayClient = new ExtendedRelayClient(
        //     ctx.container,
        //     ctx.container.get(UserContext),
        //     ctx.container.get<IContainerManager>(INTERFACES_CLI_ENTERPRISE.IContainerManager),
        //     ctx.container.get<IOutputStyler>(INTERFACES_CLI.IOutputStyler),
        //     ctx.container.get<IBetterLogger>(INTERFACES.IBetterLogger),
        //     ctx.container.get<CodiacRestClient>(CodiacRestClient),
        //     this.codiacApiUrl /* Careful! This property relies on the rest of the bootstrapping to already be done */,
        //     relayAuthToken
        //   );
        //   return relayClient;
        // });
        // RelaySocketListener.bootstrap(ioc);
        relay_websocket_client_1.RelayWebsocketClient.bootstrap(ioc);
        // NatsClient.bootstrap(ioc, {});
        const connectorSettings = { baseUrl: "nats://localhost:4222", natsInstance: bootstrapper_for_api_clients_1.BootstrapperForApiClients.RELAY_NATS_INSTANCE };
        client_1.NatsClient.bootstrap(ioc, {}, connectorSettings, bootstrapper_for_api_clients_1.BootstrapperForApiClients.RELAY_NATS_INSTANCE);
        // const connectorSettings: Partial<NatsConnectorSettings> = { baseUrl: "nats://localhost:4222" };
        // NatsClient.bootstrap(ioc, {}, connectorSettings);
        // ioc.bind(INTERFACES_CLI.IMessagingClient).to(RelayWebsocketClient).whenTargetNamed("websockets");
        ioc.bind(INTERFACES_CLI_1.INTERFACES_CLI.IMessagingClient).to(client_1.NatsClient).whenTargetNamed("nats");
        // ioc.bind(INTERFACES_CLI.IMessagingClient).to(NatsClient).whenTargetIsDefault();
        // ioc.bind(INTERFACES_CLI.IMessagingClient).toDynamicValue(ctx => {
        //   const settings = ioc.get(NatsClientSettings);
        //   const connectorSettings = ioc.getNamed(NatsConnectorSettings, BootstrapperForApiClients.RELAY_NATS_INSTANCE);
        //   const connector = ioc.getNamed<NatsConnector>(StreamingConstants.IStreamingConnector, BootstrapperForApiClients.RELAY_NATS_INSTANCE);
        //   const logger = ioc.get<IBetterLogger>(INTERFACES.IBetterLogger);
        //   const creds = ioc.getNamed<TokenCreds | undefined>(TokenCreds, BootstrapperForApiClients.RELAY_NATS_INSTANCE);
        //   const client = new NatsClient(logger, settings, connectorSettings, connector, creds);
        //   return client;
        // }).whenTargetIsDefault();
        ioc.bind(INTERFACES_CLI_1.INTERFACES_CLI.IMessagingClient)
            .toDynamicValue(ctx => ctx.container.getNamed(client_1.NatsClient, bootstrapper_for_api_clients_1.BootstrapperForApiClients.RELAY_NATS_INSTANCE))
            .whenTargetIsDefault();
        ioc.bind(lrp_watcher_predef_1.LrpWatcherPredef).toSelf();
        ioc.bind(rootmap_ui_utils_1.RootMapUiUtils).toSelf();
        this.isBootstrapped = true;
    }
}
exports.BootstrapperForEnterpriseCommands = BootstrapperForEnterpriseCommands;
BootstrapperForEnterpriseCommands.isBootstrapped = false;
//# sourceMappingURL=bootstrapper-for-enterprise-commands.js.map