"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 codiac_messaging_1 = require("@codiac.io/codiac-messaging");
const client_1 = require("@codiac.io/codiac-messaging/dist/nats/client");
const relay_container_1 = require("./relay/relay-container");
const uilogic_1 = require("./uilogic");
const entities_1 = require("./ops/entities");
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 bootstrapper_for_codiac_cli_1 = require("./bootstrapper-for-codiac-cli");
const bootstrapper_for_api_clients_1 = require("./bootstrapper-for-api-clients");
const codiac_constants_1 = require("./codiac-constants");
class BootstrapperForEnterpriseCommands {
    static bootstrap(ioc, cmd) {
        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);
        codiac_messaging_1.nats.NatsConfigurator.bootstrap(ioc, {
            natsInstance: bootstrapper_for_api_clients_1.BootstrapperForApiClients.RELAY_NATS_INSTANCE,
            connectorSettings: {
                baseUrl: cmd._cliCfg.useLocalRelay ? codiac_constants_1.CliConstants.DEFAULT_RELAY_URL : cmd._cliCfg.codiacNatsUrl,
                natsInstance: bootstrapper_for_api_clients_1.BootstrapperForApiClients.RELAY_NATS_INSTANCE
            }
        });
        ioc.bind(INTERFACES_CLI_1.INTERFACES_CLI.IMessagingClient).to(client_1.NatsClient).whenTargetNamed("nats");
        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();
        const useNats = Boolean(cmd._cliCfg.apiClientKind == entities_1.ApiClientKindEnum.nats);
        ioc.bind(uilogic_1.INTERFACES_CLI_ENTERPRISE.IContainerManager).toDynamicValue(ctx => {
            var _a;
            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, ctx.container.get(entities_1.CliConfig).localEntities);
            return relayContainer;
        });
        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