"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CodiacSdkForCli = void 0;
const uilogic_1 = require("../uilogic");
const csp_feature_enum_1 = require("../codiac-entities/csp-feature-enum");
class CodiacSdkForCli {
    /**
     *
     * @param ioc Inversion of Control container for the system.
     *
     * DEV NOTE: *let's try to keep this private by exposing type-safe public bootstrapping methods
     * that provide explicit guidance and enable the consumer to integrate their components
     * without having to know how the system is set up internally).*
     */
    constructor(ioc) {
        this.ioc = ioc;
    }
    registerCspAdapter(constructor) {
        try {
            const adapter = new constructor();
            adapter.bootstrap(this);
        }
        catch (err) {
            throw err;
        }
    }
    registerContainerRegistryConfigurator(provider, constructor) {
        if (this.ioc.isBoundNamed(uilogic_1.INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator, provider)) {
            throw new Error("Cannot re-register an IRegistryConfigurator");
        }
        else {
            this.ioc.bind(uilogic_1.INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator)
                .to(constructor)
                .whenTargetNamed(provider);
            this.updateCspSupportMap(provider, csp_feature_enum_1.CspFeatureEnum.imageRegistry);
        }
        return;
    }
    registerClusterConfigurator(provider, constructor) {
        if (this.ioc.isBoundNamed(uilogic_1.INTERFACES_CLI_ENTERPRISE.IClusterConfigurator, provider)) {
            throw new Error("Cannot re-register an IClusterConfigurator");
        }
        else {
            this.ioc.bind(uilogic_1.INTERFACES_CLI_ENTERPRISE.IClusterConfigurator)
                .to(constructor)
                .whenTargetNamed(provider);
            this.updateCspSupportMap(provider, csp_feature_enum_1.CspFeatureEnum.cluster);
        }
        return;
    }
    registerFileStoreConfigurator(provider, constructor) {
        if (this.ioc.isBoundNamed(uilogic_1.INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator, provider)) {
            throw new Error("Cannot re-register an IFileStoreConfigurator");
        }
        else {
            this.ioc.bind(uilogic_1.INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator)
                .to(constructor)
                .whenTargetNamed(provider);
            this.updateCspSupportMap(provider, csp_feature_enum_1.CspFeatureEnum.fileStore);
        }
        return;
    }
    registerSecretStoreConfigurator(provider, constructor) {
        if (this.ioc.isBoundNamed(uilogic_1.INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator, provider)) {
            throw new Error("Cannot re-register an ISecretStoreConfigurator");
        }
        else {
            this.ioc.bind(uilogic_1.INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator)
                .to(constructor)
                .whenTargetNamed(provider);
            this.updateCspSupportMap(provider, csp_feature_enum_1.CspFeatureEnum.secretStore);
        }
        return;
    }
    registerLoginConfigurator(provider, constructor) {
        if (this.ioc.isBoundNamed(uilogic_1.INTERFACES_CLI_ENTERPRISE.ILoginConfigurator, provider)) {
            throw new Error("Cannot re-register an ILoginConfigurator");
        }
        else {
            this.ioc.bind(uilogic_1.INTERFACES_CLI_ENTERPRISE.ILoginConfigurator)
                .to(constructor)
                .whenTargetNamed(provider);
        }
        return;
    }
    /** Records that this cli supports the feature for the given csp. */
    updateCspSupportMap(provider, feature) {
        var _a, _b;
        let support = (_a = this.ioc.get(uilogic_1.INTERFACES_CLI_ENTERPRISE.CspSupportMap)) !== null && _a !== void 0 ? _a : {};
        support[provider] = (_b = support[provider]) !== null && _b !== void 0 ? _b : [];
        if (!support[provider].includes(feature))
            support[provider].push(feature);
        if (this.ioc.isBound(uilogic_1.INTERFACES_CLI_ENTERPRISE.CspSupportMap)) {
            this.ioc.rebind(uilogic_1.INTERFACES_CLI_ENTERPRISE.CspSupportMap).toConstantValue(support);
        }
        else {
            this.ioc.bind(uilogic_1.INTERFACES_CLI_ENTERPRISE.CspSupportMap).toConstantValue(support);
        }
    }
}
exports.CodiacSdkForCli = CodiacSdkForCli;
//# sourceMappingURL=codiac-sdk-for-cli.js.map