// SPDX-License-Identifier: Apache-2.0
import { HelmConfigurationException } from '../helm-configuration-exception.js';
import { ShellRunner } from '../../../core/shell-runner.js';
import { OperatingSystem } from '../../../business/utils/operating-system.js';
import * as constants from '../../../core/constants.js';
/**
 * Get helm executable path
 */
export class HelmSoftwareLoader {
    static async getHelmExecutablePath() {
        try {
            const shellRunner = new ShellRunner();
            let helmPath;
            // Use the appropriate command based on the platform
            if (OperatingSystem.isLinux() || OperatingSystem.isDarwin()) {
                // eslint-disable-next-line unicorn/no-await-expression-member
                helmPath = (await shellRunner.run(`which ${constants.HELM}`)).join('').trim();
            }
            else if (OperatingSystem.isWin32()) {
                // eslint-disable-next-line unicorn/no-await-expression-member
                helmPath = (await shellRunner.run(`where ${constants.HELM}`)).join('').trim();
            }
            else {
                throw new HelmConfigurationException(`Unsupported operating system: ${OperatingSystem.getPlatform()}`);
            }
            if (!helmPath) {
                throw new HelmConfigurationException('Helm executable not found in PATH. Please install Helm and ensure it is available in your system PATH.');
            }
            return helmPath;
        }
        catch (error) {
            if (error instanceof HelmConfigurationException) {
                throw error;
            }
            throw new HelmConfigurationException(`Failed to locate Helm executable: ${error.message}`);
        }
    }
}
//# sourceMappingURL=helm-software-loader.js.map