"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());
    });
};
class LivesyncCommand {
    constructor($usbLiveSyncService, $mobileHelper, $platformService, $errors, $logger, $options) {
        this.$usbLiveSyncService = $usbLiveSyncService;
        this.$mobileHelper = $mobileHelper;
        this.$platformService = $platformService;
        this.$errors = $errors;
        this.$logger = $logger;
        this.$options = $options;
        this.allowedParameters = [];
    }
    execute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!this.$options.help && args[0]) {
                this.$logger.warn('This command is deprecated. It will be removed in the next version of NativeScript CLI. Use "$ tns run" command instead.');
            }
            yield this.$platformService.deployPlatform(args[0]);
            return this.$usbLiveSyncService.liveSync(args[0]);
        });
    }
    canExecute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            if (args.length >= 2) {
                this.$errors.fail("Invalid number of arguments.");
            }
            let platform = args[0];
            if (platform) {
                return _.includes(this.$mobileHelper.platformNames, this.$mobileHelper.normalizePlatformName(platform)) && (yield this.$platformService.validateOptions(args[0]));
            }
            else {
                return yield this.$platformService.validateOptions();
            }
        });
    }
}
exports.LivesyncCommand = LivesyncCommand;
$injector.registerCommand("livesync", LivesyncCommand);
