"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProvidersModule = void 0;
const common_1 = require("@nestjs/common");
const config_1 = require("@nestjs/config");
const typeorm_1 = require("@nestjs/typeorm");
const credential_provider_service_1 = require("./services/credential-provider.service");
const provider_credentials_repository_1 = require("../access/repositories/provider-credentials.repository");
const api_token_repository_1 = require("../access/repositories/api-token.repository");
const credentials_entity_1 = require("../access/entities/credentials.entity");
const api_token_entity_1 = require("../access/entities/api-token.entity");
const cluster_entity_1 = require("../infrastructure/clusters/entities/cluster.entity");
const provider_firewalls_controller_1 = require("./controllers/provider-firewalls.controller");
const access_module_1 = require("../access/access.module");
const provider_core_module_1 = require("./provider-core.module");
const common_module_1 = require("../common/common.module");
const shared_infrastructure_module_1 = require("../infrastructure/shared/shared-infrastructure.module");
const hetzner_provider_module_1 = require("./implementations/hetzner/hetzner-provider.module");
const hetzner_object_storage_module_1 = require("./implementations/hetzner/object-storage/hetzner-object-storage.module");
const contabo_provider_module_1 = require("./implementations/contabo/contabo-provider.module");
const scaleway_provider_module_1 = require("./implementations/scaleway/scaleway-provider.module");
const scaleway_object_storage_module_1 = require("./implementations/scaleway/object-storage/scaleway-object-storage.module");
const provider_factory_1 = require("./core/factories/provider.factory");
const firewall_provider_factory_1 = require("./core/factories/firewall-provider.factory");
const dns_provider_factory_1 = require("./core/factories/dns-provider.factory");
const capabilities_provider_factory_1 = require("./core/factories/capabilities-provider.factory");
const volume_export_factory_1 = require("./core/factories/volume-export.factory");
const object_storage_provisioner_factory_1 = require("../storage/factories/object-storage-provisioner.factory");
const storage_backend_provider_enum_1 = require("../storage/enums/storage-backend-provider.enum");
const hetzner_object_storage_provisioner_1 = require("./implementations/hetzner/object-storage/hetzner-object-storage.provisioner");
const scaleway_object_storage_provisioner_1 = require("./implementations/scaleway/object-storage/scaleway-object-storage.provisioner");
const volume_export_service_1 = require("./services/volume-export.service");
const hetzner_capabilities_service_1 = require("./implementations/hetzner/hetzner-capabilities.service");
const contabo_capabilities_service_1 = require("./implementations/contabo/contabo-capabilities.service");
const scaleway_capabilities_service_1 = require("./implementations/scaleway/scaleway-capabilities.service");
const hetzner_provider_service_1 = require("./services/hetzner-provider.service");
const hetzner_firewall_service_1 = require("./services/hetzner-firewall.service");
const hetzner_dns_service_1 = require("./services/hetzner-dns.service");
const contabo_provider_service_1 = require("./services/contabo-provider.service");
const contabo_firewall_service_1 = require("./services/contabo-firewall.service");
const scaleway_provider_service_1 = require("./implementations/scaleway/scaleway-provider.service");
const scaleway_firewall_service_1 = require("./implementations/scaleway/scaleway-firewall.service");
const scaleway_dns_service_1 = require("./implementations/scaleway/scaleway-dns.service");
const hetzner_bootstrap_seeder_service_1 = require("./implementations/hetzner/hetzner-bootstrap-seeder.service");
const scaleway_bootstrap_seeder_service_1 = require("./implementations/scaleway/scaleway-bootstrap-seeder.service");
const tokens_1 = require("./core/tokens");
const cloud_provider_enum_1 = require("./enums/cloud-provider.enum");
const dns_provider_enum_1 = require("./enums/dns-provider.enum");
let ProvidersModule = class ProvidersModule {
};
exports.ProvidersModule = ProvidersModule;
exports.ProvidersModule = ProvidersModule = __decorate([
    (0, common_1.Global)(),
    (0, common_1.Module)({
        imports: [
            config_1.ConfigModule,
            typeorm_1.TypeOrmModule.forFeature([
                credentials_entity_1.ProviderCredentialsEntity,
                api_token_entity_1.ApiTokenEntity,
                cluster_entity_1.ClusterEntity,
            ]),
            provider_core_module_1.ProviderCoreModule,
            common_module_1.CommonModule,
            shared_infrastructure_module_1.SharedInfrastructureModule,
            (0, common_1.forwardRef)(() => access_module_1.AccessModule),
            hetzner_provider_module_1.HetznerProviderModule,
            hetzner_object_storage_module_1.HetznerObjectStorageModule,
            contabo_provider_module_1.ContaboProviderModule,
            scaleway_provider_module_1.ScalewayProviderModule,
            scaleway_object_storage_module_1.ScalewayObjectStorageModule,
        ],
        controllers: [provider_firewalls_controller_1.ProviderFirewallsController],
        providers: [
            provider_credentials_repository_1.ProviderCredentialsRepository,
            api_token_repository_1.ApiTokenRepository,
            credential_provider_service_1.CredentialProviderService,
            {
                provide: 'ICredentialProvider',
                useExisting: credential_provider_service_1.CredentialProviderService,
            },
            {
                provide: provider_factory_1.ProviderFactory,
                useFactory: (hetzner, contabo, scaleway) => new provider_factory_1.ProviderFactory([
                    { provider: cloud_provider_enum_1.CloudProvider.HETZNER, service: hetzner },
                    { provider: cloud_provider_enum_1.CloudProvider.CONTABO, service: contabo },
                    { provider: cloud_provider_enum_1.CloudProvider.SCALEWAY, service: scaleway },
                ]),
                inject: [
                    hetzner_provider_service_1.HetznerProviderService,
                    contabo_provider_service_1.ContaboProviderService,
                    scaleway_provider_service_1.ScalewayProviderService,
                ],
            },
            {
                provide: firewall_provider_factory_1.FirewallProviderFactory,
                useFactory: (hetzner, contabo, scaleway) => new firewall_provider_factory_1.FirewallProviderFactory([
                    { provider: cloud_provider_enum_1.CloudProvider.HETZNER, service: hetzner },
                    { provider: cloud_provider_enum_1.CloudProvider.CONTABO, service: contabo },
                    { provider: cloud_provider_enum_1.CloudProvider.SCALEWAY, service: scaleway },
                ]),
                inject: [
                    hetzner_firewall_service_1.HetznerFirewallService,
                    contabo_firewall_service_1.ContaboFirewallService,
                    scaleway_firewall_service_1.ScalewayFirewallService,
                ],
            },
            {
                provide: dns_provider_factory_1.DnsProviderFactory,
                useFactory: (hetzner, scaleway) => new dns_provider_factory_1.DnsProviderFactory([
                    { provider: dns_provider_enum_1.DnsProvider.HETZNER, service: hetzner },
                    { provider: dns_provider_enum_1.DnsProvider.SCALEWAY, service: scaleway },
                ]),
                inject: [hetzner_dns_service_1.HetznerDnsService, scaleway_dns_service_1.ScalewayDnsService],
            },
            {
                provide: capabilities_provider_factory_1.CapabilitiesProviderFactory,
                useFactory: (hetzner, contabo, scaleway) => new capabilities_provider_factory_1.CapabilitiesProviderFactory([
                    { provider: cloud_provider_enum_1.CloudProvider.HETZNER, service: hetzner },
                    { provider: cloud_provider_enum_1.CloudProvider.CONTABO, service: contabo },
                    { provider: cloud_provider_enum_1.CloudProvider.SCALEWAY, service: scaleway },
                ]),
                inject: [
                    hetzner_capabilities_service_1.HetznerCapabilitiesService,
                    contabo_capabilities_service_1.ContaboCapabilitiesService,
                    scaleway_capabilities_service_1.ScalewayCapabilitiesService,
                ],
            },
            volume_export_service_1.VolumeExportService,
            {
                provide: object_storage_provisioner_factory_1.ObjectStorageProvisionerFactory,
                useFactory: (hetzner, scaleway) => new object_storage_provisioner_factory_1.ObjectStorageProvisionerFactory([
                    {
                        provider: storage_backend_provider_enum_1.StorageBackendProvider.HETZNER_OBJECT_STORAGE,
                        provisioner: hetzner,
                    },
                    {
                        provider: storage_backend_provider_enum_1.StorageBackendProvider.SCALEWAY_OBJECT_STORAGE,
                        provisioner: scaleway,
                    },
                ]),
                inject: [
                    hetzner_object_storage_provisioner_1.HetznerObjectStorageProvisioner,
                    scaleway_object_storage_provisioner_1.ScalewayObjectStorageProvisioner,
                ],
            },
            {
                provide: volume_export_factory_1.VolumeExportFactory,
                useFactory: (universal) => new volume_export_factory_1.VolumeExportFactory([
                    { provider: cloud_provider_enum_1.CloudProvider.HETZNER, service: universal },
                    { provider: cloud_provider_enum_1.CloudProvider.SCALEWAY, service: universal },
                    { provider: cloud_provider_enum_1.CloudProvider.CONTABO, service: universal },
                ]),
                inject: [volume_export_service_1.VolumeExportService],
            },
            {
                provide: tokens_1.PROVIDER_BOOTSTRAP_SEEDER_REGISTRY,
                useFactory: (hetzner, scaleway) => [
                    { provider: cloud_provider_enum_1.CloudProvider.HETZNER, service: hetzner },
                    { provider: cloud_provider_enum_1.CloudProvider.SCALEWAY, service: scaleway },
                ],
                inject: [hetzner_bootstrap_seeder_service_1.HetznerBootstrapSeeder, scaleway_bootstrap_seeder_service_1.ScalewayBootstrapSeeder],
            },
        ],
        exports: [
            provider_core_module_1.ProviderCoreModule,
            credential_provider_service_1.CredentialProviderService,
            'ICredentialProvider',
            hetzner_provider_module_1.HetznerProviderModule,
            hetzner_object_storage_module_1.HetznerObjectStorageModule,
            contabo_provider_module_1.ContaboProviderModule,
            scaleway_provider_module_1.ScalewayProviderModule,
            scaleway_object_storage_module_1.ScalewayObjectStorageModule,
            provider_factory_1.ProviderFactory,
            firewall_provider_factory_1.FirewallProviderFactory,
            dns_provider_factory_1.DnsProviderFactory,
            capabilities_provider_factory_1.CapabilitiesProviderFactory,
            volume_export_factory_1.VolumeExportFactory,
            object_storage_provisioner_factory_1.ObjectStorageProvisionerFactory,
            tokens_1.PROVIDER_BOOTSTRAP_SEEDER_REGISTRY,
        ],
    })
], ProvidersModule);
