"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 RunCommandBase {
    constructor($platformService, $usbLiveSyncService, $options) {
        this.$platformService = $platformService;
        this.$usbLiveSyncService = $usbLiveSyncService;
        this.$options = $options;
    }
    executeCore(args) {
        return __awaiter(this, void 0, void 0, function* () {
            yield this.$platformService.deployPlatform(args[0]);
            if (this.$options.bundle) {
                this.$options.watch = false;
            }
            if (this.$options.release) {
                return this.$platformService.runPlatform(args[0]);
            }
            return this.$usbLiveSyncService.liveSync(args[0]);
        });
    }
}
exports.RunCommandBase = RunCommandBase;
class RunIosCommand extends RunCommandBase {
    constructor($platformService, $platformsData, $usbLiveSyncService, $options) {
        super($platformService, $usbLiveSyncService, $options);
        this.$platformsData = $platformsData;
        this.allowedParameters = [];
    }
    execute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
        });
    }
    canExecute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            return args.length === 0 && (yield this.$platformService.validateOptions(this.$platformsData.availablePlatforms.iOS));
        });
    }
}
exports.RunIosCommand = RunIosCommand;
$injector.registerCommand("run|ios", RunIosCommand);
class RunAndroidCommand extends RunCommandBase {
    constructor($platformService, $platformsData, $usbLiveSyncService, $options, $errors) {
        super($platformService, $usbLiveSyncService, $options);
        this.$platformsData = $platformsData;
        this.$errors = $errors;
        this.allowedParameters = [];
    }
    execute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            return this.executeCore([this.$platformsData.availablePlatforms.Android]);
        });
    }
    canExecute(args) {
        return __awaiter(this, void 0, void 0, function* () {
            if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
                this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
            }
            return args.length === 0 && (yield this.$platformService.validateOptions(this.$platformsData.availablePlatforms.Android));
        });
    }
}
exports.RunAndroidCommand = RunAndroidCommand;
$injector.registerCommand("run|android", RunAndroidCommand);
