"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_base_1 = require("./command-base");
class AddPlatformCommand extends command_base_1.ValidatePlatformCommandBase {
    constructor($options, $platformCommandHelper, $platformValidationService, $projectData, $platformsDataService, $errors) {
        super($options, $platformsDataService, $platformValidationService, $projectData);
        this.$platformCommandHelper = $platformCommandHelper;
        this.$errors = $errors;
        this.allowedParameters = [];
        this.$projectData.initializeProjectData();
    }
    execute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.$platformCommandHelper.addPlatforms(args, this.$projectData, this.$options.frameworkPath);
        });
    }
    canExecute(args) {
        const _super = Object.create(null, {
            canExecuteCommandBase: { get: () => super.canExecuteCommandBase }
        });
        return __awaiter(this, void 0, void 0, function* () {
            if (!args || args.length === 0) {
                this.$errors.fail("No platform specified. Please specify a platform to add");
            }
            let canExecute = true;
            for (const arg of args) {
                this.$platformValidationService.validatePlatform(arg, this.$projectData);
                if (!this.$platformValidationService.isPlatformSupportedForOS(arg, this.$projectData)) {
                    this.$errors.fail(`Applications for platform ${arg} can not be built on this OS`);
                }
                const output = yield _super.canExecuteCommandBase.call(this, arg);
                canExecute = canExecute && output.canExecute;
            }
            return {
                canExecute,
                suppressCommandHelp: !canExecute
            };
        });
    }
}
exports.AddPlatformCommand = AddPlatformCommand;
$injector.registerCommand("platform|add", AddPlatformCommand);
