"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UpdatePlatformCommand = void 0;
const _ = require("lodash");
const yok_1 = require("../common/yok");
class UpdatePlatformCommand {
    constructor($errors, $options, $platformEnvironmentRequirements, $platformCommandHelper, $platformValidationService, $projectData) {
        this.$errors = $errors;
        this.$options = $options;
        this.$platformEnvironmentRequirements = $platformEnvironmentRequirements;
        this.$platformCommandHelper = $platformCommandHelper;
        this.$platformValidationService = $platformValidationService;
        this.$projectData = $projectData;
        this.allowedParameters = [];
        this.$projectData.initializeProjectData();
    }
    async execute(args) {
        await this.$platformCommandHelper.updatePlatforms(args, this.$projectData);
    }
    async canExecute(args) {
        if (!args || args.length === 0) {
            this.$errors.failWithHelp("No platform specified. Please specify platforms to update.");
        }
        _.each(args, (arg) => {
            const platform = arg.split("@")[0];
            this.$platformValidationService.validatePlatform(platform, this.$projectData);
        });
        for (const arg of args) {
            const [platform, versionToBeInstalled] = arg.split("@");
            const checkEnvironmentRequirementsInput = {
                platform,
                options: this.$options,
            };
            if (versionToBeInstalled) {
                checkEnvironmentRequirementsInput.projectDir = this.$projectData.projectDir;
                checkEnvironmentRequirementsInput.runtimeVersion = versionToBeInstalled;
            }
            await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(checkEnvironmentRequirementsInput);
        }
        return true;
    }
}
exports.UpdatePlatformCommand = UpdatePlatformCommand;
yok_1.injector.registerCommand("platform|update", UpdatePlatformCommand);
