"use strict";
var ClusterConfiguratorFactory_1, LoginConfiguratorFactory_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LoginConfiguratorFactory = exports.SecretStoreConfiguratorFactory = exports.FileStoreConfiguratorFactory = exports.ClusterConfiguratorFactory = exports.RegistryConfiguratorFactory = exports.INTERFACES_CLI_ENTERPRISE = void 0;
const tslib_1 = require("tslib");
const codiac_domain_1 = require("@codiac.io/codiac-domain");
const inversify_1 = require("inversify");
const aws_1 = require("../sdk-adapters/aws");
const azure_1 = require("../sdk-adapters/azure");
const azure_2 = require("../sdk-adapters/azure");
const docker_hub_1 = require("../sdk-adapters/docker-hub");
const artifact_hub_1 = require("../sdk-adapters/artifact-hub");
const local_machine_resource_configurator_1 = require("../sdk-adapters/local-machine/local-machine-resource-configurator");
const local_machine_login_configurator_1 = require("../sdk-adapters/local-machine/local-machine-login-configurator");
class INTERFACES_CLI_ENTERPRISE {
}
exports.INTERFACES_CLI_ENTERPRISE = INTERFACES_CLI_ENTERPRISE;
INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator = Symbol.for("IRegistryConfigurator");
INTERFACES_CLI_ENTERPRISE.IClusterConfigurator = Symbol.for("IClusterConfigurator");
INTERFACES_CLI_ENTERPRISE.ICodiacClient = Symbol.for("ICodiacClient");
INTERFACES_CLI_ENTERPRISE.IAuthClient = Symbol.for("IAuthClient");
INTERFACES_CLI_ENTERPRISE.IContainerManager = Symbol.for("IContainerManager");
INTERFACES_CLI_ENTERPRISE.ILoginConfigurator = Symbol.for("ILoginConfigurator");
INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator = Symbol.for("ISecretStoreConfigurator");
INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator = Symbol.for("IFileStoreConfigurator");
INTERFACES_CLI_ENTERPRISE.CspSupportMap = Symbol.for("CspSupportMap");
let RegistryConfiguratorFactory = class RegistryConfiguratorFactory {
    /** Idempotent. */
    static bootstrap(ioc) {
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator, codiac_domain_1.CloudProviderEnum.aws)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator)
                .to(aws_1.AwsResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.aws);
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator, codiac_domain_1.CloudProviderEnum.azure)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator)
                .to(azure_1.AzureResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.azure);
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator, codiac_domain_1.CloudProviderEnum.dockerHub)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator)
                .to(docker_hub_1.DockerHubResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.dockerHub);
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator, codiac_domain_1.CloudProviderEnum.other)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator)
                .to(artifact_hub_1.HelmResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.other);
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator, codiac_domain_1.CloudProviderEnum.artifactHub)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator)
                .to(artifact_hub_1.HelmResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.artifactHub);
        }
    }
    constructor() {
    }
    create(provider, ioc) {
        return ioc.getNamed(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator, provider);
    }
};
RegistryConfiguratorFactory = tslib_1.__decorate([
    (0, inversify_1.injectable)(),
    tslib_1.__metadata("design:paramtypes", [])
], RegistryConfiguratorFactory);
exports.RegistryConfiguratorFactory = RegistryConfiguratorFactory;
let ClusterConfiguratorFactory = ClusterConfiguratorFactory_1 = class ClusterConfiguratorFactory {
    /** Idempotent. */
    static bootstrap(ioc, cmd) {
        if (this.isBootstrapped !== true) {
            if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IClusterConfigurator, codiac_domain_1.CloudProviderEnum.aws)) {
                ioc.bind(INTERFACES_CLI_ENTERPRISE.IClusterConfigurator)
                    .to(aws_1.AwsResourceConfigurator)
                    .whenTargetNamed(codiac_domain_1.CloudProviderEnum.aws);
            }
            if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IClusterConfigurator, codiac_domain_1.CloudProviderEnum.azure)) {
                ioc.bind(INTERFACES_CLI_ENTERPRISE.IClusterConfigurator)
                    .to(azure_1.AzureResourceConfigurator)
                    .whenTargetNamed(codiac_domain_1.CloudProviderEnum.azure);
            }
            // local data feature flag 
            // const localEntities = TypeSafetyUtils.toBoolean(/* TEMP HACK!! --> update this class... */(<any>cmd.localConfig)?.localEntities ?? cmd._cliCfg?.localEntities);
            // if (localEntities) {
            if (cmd._cliCfg.localEntities) {
                if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IClusterConfigurator, codiac_domain_1.CloudProviderEnum.localMachine)) {
                    ioc.bind(INTERFACES_CLI_ENTERPRISE.IClusterConfigurator)
                        .to(local_machine_resource_configurator_1.LocalMachineResourceConfigurator)
                        .whenTargetNamed(codiac_domain_1.CloudProviderEnum.localMachine);
                }
            }
            if (!ioc.isBound(ClusterConfiguratorFactory_1)) {
                ioc.bind(ClusterConfiguratorFactory_1).toSelf();
            }
            this.isBootstrapped = true;
        }
    }
    constructor() {
    }
    create(provider, ioc) {
        return ioc.getNamed(INTERFACES_CLI_ENTERPRISE.IClusterConfigurator, provider);
    }
    getAllClusterProviders(ioc) {
        return ioc.getAll(INTERFACES_CLI_ENTERPRISE.IClusterConfigurator).map(x => x.cloudProvider);
    }
    getAllFileStoreProviders(ioc) {
        return ioc.getAll(INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator).map(x => x.cloudProvider);
    }
    getAllRegistryProviders(ioc) {
        return ioc.getAll(INTERFACES_CLI_ENTERPRISE.IRegistryConfigurator).map(x => x.cloudProvider);
    }
    getAllSecretStoreProviders(ioc) {
        return ioc.getAll(INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator).map(x => x.cloudProvider);
    }
};
ClusterConfiguratorFactory = ClusterConfiguratorFactory_1 = tslib_1.__decorate([
    (0, inversify_1.injectable)(),
    tslib_1.__metadata("design:paramtypes", [])
], ClusterConfiguratorFactory);
exports.ClusterConfiguratorFactory = ClusterConfiguratorFactory;
let FileStoreConfiguratorFactory = class FileStoreConfiguratorFactory {
    /** Idempotent. */
    static bootstrap(ioc) {
        // NOT YET SUPPORTED.  Apparently mounting S3 buckets requires a host volume and therefore an accompanying Daemonset.  It's not worth it when we can support EFS and EBS instead.
        // if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator, CloudProviderEnum.aws)) {
        //   ioc.bind<IFileStoreConfigurator>(INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator)
        //     .to(AwsResourceConfigurator)
        //     .whenTargetNamed(CloudProviderEnum.aws);
        // }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator, codiac_domain_1.CloudProviderEnum.azure)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator)
                .to(azure_1.AzureResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.azure);
        }
    }
    constructor(ioc) {
        this.ioc = ioc;
    }
    create(provider, ioc) {
        return (ioc !== null && ioc !== void 0 ? ioc : this.ioc).getNamed(INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator, provider);
    }
    getAllProviders(ioc) {
        return (ioc !== null && ioc !== void 0 ? ioc : this.ioc).getAll(INTERFACES_CLI_ENTERPRISE.IFileStoreConfigurator).map(x => x.cloudProvider);
    }
};
FileStoreConfiguratorFactory = tslib_1.__decorate([
    (0, inversify_1.injectable)(),
    tslib_1.__metadata("design:paramtypes", [Object])
], FileStoreConfiguratorFactory);
exports.FileStoreConfiguratorFactory = FileStoreConfiguratorFactory;
let SecretStoreConfiguratorFactory = class SecretStoreConfiguratorFactory {
    /** Idempotent. */
    static bootstrap(ioc) {
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator, codiac_domain_1.CloudProviderEnum.aws)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator)
                .to(aws_1.AwsResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.aws);
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator, codiac_domain_1.CloudProviderEnum.azure)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator)
                .to(azure_1.AzureResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.azure);
        }
    }
    constructor() {
    }
    create(provider, ioc) {
        return ioc.getNamed(INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator, provider);
    }
    getAllProviders(ioc) {
        return ioc.getAll(INTERFACES_CLI_ENTERPRISE.ISecretStoreConfigurator).map(x => x.cloudProvider);
    }
};
SecretStoreConfiguratorFactory = tslib_1.__decorate([
    (0, inversify_1.injectable)(),
    tslib_1.__metadata("design:paramtypes", [])
], SecretStoreConfiguratorFactory);
exports.SecretStoreConfiguratorFactory = SecretStoreConfiguratorFactory;
let LoginConfiguratorFactory = LoginConfiguratorFactory_1 = class LoginConfiguratorFactory {
    /** Idempotent. */
    static bootstrap(ioc) {
        if (!ioc.isBound(LoginConfiguratorFactory_1)) {
            ioc.bind(LoginConfiguratorFactory_1).toSelf();
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator, codiac_domain_1.CloudProviderEnum.aws)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator)
                .to(aws_1.AwsResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.aws);
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator, codiac_domain_1.CloudProviderEnum.azure)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator)
                // .to(AzureResourceConfigurator)
                .to(azure_2.AzureInteractiveLoginConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.azure);
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator, codiac_domain_1.CloudProviderEnum.dockerHub)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator)
                .to(docker_hub_1.DockerHubResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.dockerHub);
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator, codiac_domain_1.CloudProviderEnum.artifactHub)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator)
                .to(artifact_hub_1.HelmResourceConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.artifactHub);
        }
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator, codiac_domain_1.CloudProviderEnum.localMachine)) {
            ioc.bind(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator)
                .to(local_machine_login_configurator_1.LocalMachineLoginConfigurator)
                .whenTargetNamed(codiac_domain_1.CloudProviderEnum.localMachine);
        }
    }
    constructor() {
    }
    create(provider, ioc) {
        if (!ioc.isBoundNamed(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator, provider)) {
            throw new Error(`No login configurator is registered for ${provider}.`);
        }
        return ioc.getNamed(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator, provider);
    }
    getAllProviders(ioc) {
        return ioc.getAll(INTERFACES_CLI_ENTERPRISE.ILoginConfigurator).map(x => x.cloudProvider);
    }
};
LoginConfiguratorFactory = LoginConfiguratorFactory_1 = tslib_1.__decorate([
    (0, inversify_1.injectable)(),
    tslib_1.__metadata("design:paramtypes", [])
], LoginConfiguratorFactory);
exports.LoginConfiguratorFactory = LoginConfiguratorFactory;
//# sourceMappingURL=cloud-resource-configurator-factory.js.map