"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, $projectData, $errors, $logger, $options) {
        this.$usbLiveSyncService = $usbLiveSyncService;
        this.$mobileHelper = $mobileHelper;
        this.$platformService = $platformService;
        this.$projectData = $projectData;
        this.$errors = $errors;
        this.$logger = $logger;
        this.$options = $options;
        this.allowedParameters = [];
        this.$projectData.initializeProjectData();
    }
    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.');
            }
            const appFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
            const deployOptions = {
                clean: this.$options.clean,
                device: this.$options.device,
                emulator: this.$options.emulator,
                projectDir: this.$options.path,
                platformTemplate: this.$options.platformTemplate,
                release: this.$options.release,
                provision: this.$options.provision,
                teamId: this.$options.teamId
            };
            yield this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
            return this.$usbLiveSyncService.liveSync(args[0], this.$projectData);
        });
    }
    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(this.$options.provision, this.$projectData, args[0]));
            }
            else {
                return yield this.$platformService.validateOptions(this.$options.provision, this.$projectData);
            }
        });
    }
}
exports.LivesyncCommand = LivesyncCommand;
$injector.registerCommand("livesync", LivesyncCommand);
