"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AddPluginCommand = void 0;
const _ = require("lodash");
const yok_1 = require("../../common/yok");
class AddPluginCommand {
    constructor($pluginsService, $projectData, $errors) {
        this.$pluginsService = $pluginsService;
        this.$projectData = $projectData;
        this.$errors = $errors;
        this.allowedParameters = [];
        this.$projectData.initializeProjectData();
    }
    async execute(args) {
        return this.$pluginsService.add(args[0], this.$projectData);
    }
    async canExecute(args) {
        if (!args[0]) {
            this.$errors.failWithHelp("You must specify plugin name.");
        }
        const installedPlugins = await this.$pluginsService.getAllInstalledPlugins(this.$projectData);
        const pluginName = args[0].toLowerCase();
        if (_.some(installedPlugins, (plugin) => plugin.name.toLowerCase() === pluginName)) {
            this.$errors.fail(`Plugin "${pluginName}" is already installed.`);
        }
        return true;
    }
}
exports.AddPluginCommand = AddPluginCommand;
yok_1.injector.registerCommand(["plugin|add", "plugin|install"], AddPluginCommand);
