import constants from '../constants.js';
import OutputManager from '../outputManager.js';
import StatusManager from '../statusManager.js';
import LocalDockerWrapper from './localDockerWrapper.js';
import RemoteDockerWrapper from './remoteDockerWrapper.js';
export default class DockerManager {
    static dockerWrapper;
    static async dispose() {
        if (this.dockerWrapper) {
            await this.dockerWrapper.dispose();
        }
    }
    static async get() {
        if (!this.dockerWrapper) {
            StatusManager.startTask("Initializing runtime environment");
            const remoteDockerWrapper = new RemoteDockerWrapper();
            const localDockerWrapper = new LocalDockerWrapper();
            if (await remoteDockerWrapper.isAvailable()) {
                OutputManager.detail("Using remote Docker");
                this.dockerWrapper = remoteDockerWrapper;
            }
            else if (await localDockerWrapper.isAvailable()) {
                OutputManager.detail("Using local Docker");
                this.dockerWrapper = localDockerWrapper;
            }
            else {
                throw new Error(`Docker not found. You can either install and run Docker on your local machine or deploy a Cloud Scripts Build Host in Kyndryl Cloud Uplift. To deploy in Kyndryl Cloud Uplift, please configure your Kyndryl Cloud Uplift API credentials (see \`${constants.APP_NAME} cloud login --help\`) and then provision (see \`${constants.APP_NAME} build-host provision --help\`).`);
            }
            await this.dockerWrapper.start();
            await this.dockerWrapper.prepare();
        }
        return this.dockerWrapper.get();
    }
}
