// SPDX-License-Identifier: Apache-2.0
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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import * as constants from './constants.js';
import { patchInject } from './dependency-injection/container-helper.js';
import { inject, injectable } from 'tsyringe-neo';
import { InjectTokens } from './dependency-injection/inject-tokens.js';
/**
 * Class to check if certain components are installed in the cluster.
 */
let ClusterChecks = class ClusterChecks {
    logger;
    k8Factory;
    constructor(logger, k8Factory) {
        this.logger = logger;
        this.k8Factory = k8Factory;
        this.logger = patchInject(logger, InjectTokens.SoloLogger, this.constructor.name);
        this.k8Factory = patchInject(k8Factory, InjectTokens.K8Factory, this.constructor.name);
    }
    /**
     * Check if cert-manager is installed inside any namespace.
     * @returns if cert-manager is found
     */
    async isCertManagerInstalled() {
        try {
            const pods = await this.k8Factory.default().pods().listForAllNamespaces(['app=cert-manager']);
            return pods.length > 0;
        }
        catch (error) {
            this.logger.error('Failed to find cert-manager:', error);
            return false;
        }
    }
    /**
     * Check if minio is installed inside the namespace.
     * @returns if minio is found
     */
    async isMinioInstalled(namespace) {
        try {
            // TODO DETECT THE OPERATOR
            const pods = await this.k8Factory.default().pods().list(namespace, ['app=minio']);
            return pods.length > 0;
        }
        catch (error) {
            this.logger.error('Failed to find minio:', error);
            return false;
        }
    }
    /**
     * Check if the ingress controller is installed inside any namespace.
     * @returns if ingress controller is found
     */
    async isIngressControllerInstalled() {
        try {
            const ingressClassList = await this.k8Factory.default().ingressClasses().list();
            return ingressClassList.length > 0;
        }
        catch (error) {
            this.logger.error('Failed to find ingress controller:', error);
            return false;
        }
    }
    /**
     * Check if the remote config is installed inside any namespace.
     * @returns if remote config is found
     */
    async isRemoteConfigPresentInAnyNamespace(context) {
        try {
            const configmaps = await this.k8Factory
                .getK8(context)
                .configMaps()
                .listForAllNamespaces([constants.SOLO_REMOTE_CONFIGMAP_LABEL_SELECTOR]);
            return configmaps.length > 0;
        }
        catch (error) {
            this.logger.error('Failed to find remote config:', error);
            return false;
        }
    }
    /**
     * Searches specific namespace for remote config's config map
     *
     * @param namespace - namespace where to search
     * @returns true if found else false
     */
    async isRemoteConfigPresentInNamespace(namespace) {
        try {
            const configmaps = await this.k8Factory
                .default()
                .configMaps()
                .list(namespace, [constants.SOLO_REMOTE_CONFIGMAP_LABEL_SELECTOR]);
            return configmaps.length > 0;
        }
        catch (error) {
            this.logger.error('Failed to find remote config:', error);
            return false;
        }
    }
};
ClusterChecks = __decorate([
    injectable(),
    __param(0, inject(InjectTokens.SoloLogger)),
    __param(1, inject(InjectTokens.K8Factory)),
    __metadata("design:paramtypes", [Object, Object])
], ClusterChecks);
export { ClusterChecks };
//# sourceMappingURL=cluster-checks.js.map