"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BootstrapperForTenantlessCommands = void 0;
require("reflect-metadata");
const ops_1 = require("./ops");
const codiac_relay_contracts_1 = require("@codiac.io/codiac-relay-contracts");
const workspace_versioner_1 = require("./ops/workspace-versioner");
const entities_1 = require("./ops/entities");
const data_1 = require("./ops/data");
const bootstrapper_for_codiac_cli_1 = require("./bootstrapper-for-codiac-cli");
class BootstrapperForTenantlessCommands {
    static bootstrap(ioc, cmd) {
        if (this.isBootstrapped == true) {
            return;
        }
        cmd.requiresProjectScope = true;
        bootstrapper_for_codiac_cli_1.BootstrapperForCodiacCli.bootstrap(ioc, cmd.config, cmd.requiresProjectScope);
        // REBIND PROJECT SCOPE AS NON-nullable
        if (ioc.isBound(entities_1.ProjectEnviro))
            ioc.unbind(entities_1.ProjectEnviro);
        ioc.bind(entities_1.ProjectEnviro).toDynamicValue(() => {
            let projRoot = ops_1.CliPathWalker.getProjectRoot(undefined, true);
            return new entities_1.ProjectEnviro(projRoot);
        }).inSingletonScope();
        if (ioc.isBound(data_1.ProjectContextRepo))
            ioc.unbind(data_1.ProjectContextRepo);
        ioc.bind(data_1.ProjectContextRepo).toSelf(); // (() => new CliContextRepo(this.config.configDir, this._projectRoot));
        if (ioc.isBound(codiac_relay_contracts_1.ProjectConfig))
            ioc.unbind(codiac_relay_contracts_1.ProjectConfig);
        ioc.bind(codiac_relay_contracts_1.ProjectConfig).toDynamicValue(ctxt => {
            let cfgRepo = ctxt.container.get(data_1.ProjectContextRepo);
            return cfgRepo.readProjectConfig();
        }); // .inSingletonScope();
        if (ioc.isBound(codiac_relay_contracts_1.ProjectUserConfig))
            ioc.unbind(codiac_relay_contracts_1.ProjectUserConfig);
        ioc.bind(codiac_relay_contracts_1.ProjectUserConfig).toDynamicValue(ctxt => {
            let cfgRepo = ctxt.container.get(data_1.ProjectContextRepo);
            return cfgRepo.readProjectUserConfig();
        }); // .inSingletonScope();
        if (ioc.isBound(workspace_versioner_1.SemanticVersioner))
            ioc.unbind(workspace_versioner_1.SemanticVersioner);
        ioc.bind(workspace_versioner_1.SemanticVersioner).toSelf();
        if (ioc.isBound(workspace_versioner_1.WorkspaceVersioner))
            ioc.unbind(workspace_versioner_1.WorkspaceVersioner);
        ioc.bind(workspace_versioner_1.WorkspaceVersioner).toSelf();
        this.isBootstrapped = true;
    }
}
exports.BootstrapperForTenantlessCommands = BootstrapperForTenantlessCommands;
BootstrapperForTenantlessCommands.isBootstrapped = false;
//# sourceMappingURL=bootstrapper-for-tenantless-commands.js.map