// 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 os from 'node:os';
import { SoloError } from '../errors/solo-error.js';
import { ShellRunner } from '../shell-runner.js';
import { HelmDependencyManager } from './helm-dependency-manager.js';
import { container, inject, injectable } from 'tsyringe-neo';
import * as constants from '../constants.js';
import { InjectTokens } from '../dependency-injection/inject-tokens.js';
import { KindDependencyManager } from './kind-dependency-manager.js';
import { KubectlDependencyManager } from './kubectl-dependency-manager.js';
import { PodmanDependencyManager } from './podman-dependency-manager.js';
import { VfkitDependencyManager } from './vfkit-dependency-manager.js';
import { GvproxyDependencyManager } from './gvproxy-dependency-manager.js';
let DependencyManager = class DependencyManager extends ShellRunner {
    dependancyManagerMap;
    constructor(helmDepManager, kindDepManager, kubectlDependencyManager, podmanDependencyManager, vfkitDependencyManager, gvproxyDependencyManager) {
        super();
        this.dependancyManagerMap = new Map();
        this.dependancyManagerMap.set(constants.HELM, helmDepManager || container.resolve(InjectTokens.HelmDependencyManager));
        this.dependancyManagerMap.set(constants.KIND, kindDepManager || container.resolve(InjectTokens.KindDependencyManager));
        this.dependancyManagerMap.set(constants.KUBECTL, kubectlDependencyManager || container.resolve(InjectTokens.KubectlDependencyManager));
        this.dependancyManagerMap.set(constants.PODMAN, podmanDependencyManager || container.resolve(InjectTokens.PodmanDependencyManager));
        this.dependancyManagerMap.set(constants.VFKIT, vfkitDependencyManager || container.resolve(InjectTokens.VfkitDependencyManager));
        this.dependancyManagerMap.set(constants.GVPROXY, gvproxyDependencyManager || container.resolve(InjectTokens.GvproxyDependencyManager));
    }
    async getDependency(dep) {
        const manager = this.dependancyManagerMap.get(dep);
        if (manager) {
            return manager;
        }
        throw new SoloError(`Dependency manager for '${dep}' is not found`);
    }
    /**
     * Check if the required dependency is installed or not
     * @param dep - is the name of the program
     */
    async checkDependency(dep) {
        this.logger.debug(`Checking for dependency: ${dep}`);
        let status = false;
        const manager = this.dependancyManagerMap.get(dep);
        if (manager) {
            status = await manager.install();
        }
        if (!status) {
            throw new SoloError(`Dependency '${dep}' is not found`);
        }
        this.logger.debug(`Dependency '${dep}' is found`);
        return true;
    }
    async skipDependency(dep) {
        let skip = false;
        const manager = this.dependancyManagerMap.get(dep);
        if (manager) {
            skip = !(await manager.shouldInstall());
        }
        this.logger.debug(`Skipping install of for dependency: ${dep}: ${skip}`);
        return skip;
    }
    taskCheckDependencies(deps) {
        return deps.map(dep => {
            return {
                title: `Check dependency: ${dep} [OS: ${os.platform()}, Release: ${os.release()}, Arch: ${os.arch()}]`,
                task: () => this.checkDependency(dep),
                skip: () => this.skipDependency(dep),
            };
        });
    }
    async getExecutablePath(dep) {
        const manager = this.dependancyManagerMap.get(dep);
        if (manager) {
            return await manager.getExecutablePath();
        }
        throw new SoloError(`Dependency manager for '${dep}' is not found`);
    }
};
DependencyManager = __decorate([
    injectable(),
    __param(0, inject(InjectTokens.HelmDependencyManager)),
    __param(1, inject(InjectTokens.KindDependencyManager)),
    __param(2, inject(InjectTokens.KubectlDependencyManager)),
    __param(3, inject(InjectTokens.PodmanDependencyManager)),
    __param(4, inject(InjectTokens.VfkitDependencyManager)),
    __param(5, inject(InjectTokens.GvproxyDependencyManager)),
    __metadata("design:paramtypes", [HelmDependencyManager,
        KindDependencyManager,
        KubectlDependencyManager,
        PodmanDependencyManager,
        VfkitDependencyManager,
        GvproxyDependencyManager])
], DependencyManager);
export { DependencyManager };
//# sourceMappingURL=dependency-manager.js.map