import * as helpers from '../../core/helpers.js';
import * as constants from '../../core/constants.js';
import * as ContextFlags from './flags.js';
import { RemoteConfigTasks } from '../../core/config/remote/remote_config_tasks.js';
import { connectConfigBuilder, resetConfigBuilder, setupConfigBuilder } from './configs.js';
import { SoloError } from '../../core/errors.js';
export class ClusterCommandHandlers {
    parent;
    tasks;
    remoteConfigManager;
    getConfig;
    constructor(parent, tasks, remoteConfigManager) {
        this.parent = parent;
        this.tasks = tasks;
        this.remoteConfigManager = remoteConfigManager;
        this.getConfig = parent.getConfig.bind(parent);
    }
    async connect(argv) {
        argv = helpers.addFlagsToArgv(argv, ContextFlags.USE_FLAGS);
        const action = this.parent.commandActionBuilder([
            this.tasks.initialize(argv, connectConfigBuilder.bind(this)),
            this.tasks.setupHomeDirectory(),
            this.parent.getLocalConfig().promptLocalConfigTask(this.parent.getK8()),
            this.tasks.selectContext(argv),
            RemoteConfigTasks.loadRemoteConfig.bind(this)(argv),
            this.tasks.updateLocalConfig(argv),
        ], {
            concurrent: false,
            rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
        }, 'cluster connect', null);
        await action(argv, this);
        return true;
    }
    async list(argv) {
        argv = helpers.addFlagsToArgv(argv, ContextFlags.USE_FLAGS);
        const action = this.parent.commandActionBuilder([this.tasks.showClusterList()], {
            concurrent: false,
            rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
        }, 'cluster list', null);
        await action(argv, this);
        return true;
    }
    async info(argv) {
        argv = helpers.addFlagsToArgv(argv, ContextFlags.USE_FLAGS);
        const action = this.parent.commandActionBuilder([this.tasks.getClusterInfo()], {
            concurrent: false,
            rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
        }, 'cluster info', null);
        await action(argv, this);
        return true;
    }
    async setup(argv) {
        argv = helpers.addFlagsToArgv(argv, ContextFlags.USE_FLAGS);
        const action = this.parent.commandActionBuilder([
            this.tasks.initialize(argv, setupConfigBuilder.bind(this)),
            this.tasks.prepareChartValues(argv),
            this.tasks.installClusterChart(argv),
        ], {
            concurrent: false,
            rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
        }, 'cluster setup', null);
        try {
            await action(argv, this);
        }
        catch (e) {
            throw new SoloError('Error on cluster setup', e);
        }
        return true;
    }
    async reset(argv) {
        argv = helpers.addFlagsToArgv(argv, ContextFlags.USE_FLAGS);
        const action = this.parent.commandActionBuilder([
            this.tasks.initialize(argv, resetConfigBuilder.bind(this)),
            this.tasks.acquireNewLease(argv),
            this.tasks.uninstallClusterChart(argv),
        ], {
            concurrent: false,
            rendererOptions: constants.LISTR_DEFAULT_RENDERER_OPTION,
        }, 'cluster reset', null);
        try {
            await action(argv, this);
        }
        catch (e) {
            throw new SoloError('Error on cluster reset', e);
        }
        return true;
    }
}
//# sourceMappingURL=handlers.js.map