"use strict";
class DebugPlatformCommand {
    constructor(debugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $options) {
        this.debugService = debugService;
        this.$devicesService = $devicesService;
        this.$injector = $injector;
        this.$logger = $logger;
        this.$childProcess = $childProcess;
        this.$devicePlatformsConstants = $devicePlatformsConstants;
        this.$config = $config;
        this.$usbLiveSyncService = $usbLiveSyncService;
        this.$options = $options;
        this.allowedParameters = [];
    }
    execute(args) {
        if (this.$options.watch) {
            this.$options.rebuild = false;
        }
        if (!this.$options.rebuild && !this.$options.start) {
            this.$config.debugLivesync = true;
            let applicationReloadAction = (deviceAppData, localToDevicePaths) => {
                return (() => {
                    let projectData = this.$injector.resolve("projectData");
                    this.debugService.debugStop().wait();
                    let applicationId = deviceAppData.appIdentifier;
                    if (deviceAppData.device.isEmulator && deviceAppData.platform.toLowerCase() === this.$devicePlatformsConstants.iOS.toLowerCase()) {
                        applicationId = projectData.projectName;
                    }
                    deviceAppData.device.applicationManager.stopApplication(applicationId).wait();
                    this.debugService.debug().wait();
                }).future()();
            };
            return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, applicationReloadAction);
        }
        return this.debugService.debug();
    }
    canExecute(args) {
        return (() => {
            this.$devicesService.initialize({ platform: this.debugService.platform, deviceId: this.$options.device }).wait();
            if (this.$options.emulator || this.$devicesService.deviceCount === 0) {
                return true;
            }
            if (this.$devicesService.deviceCount > 1) {
                this.$options.emulator = true;
                this.$logger.warn("Multiple devices found! Starting debugger on emulator. If you want to debug on specific device please select device with --device option.".yellow.bold);
            }
            return true;
        }).future()();
    }
}
exports.DebugPlatformCommand = DebugPlatformCommand;
class DebugIOSCommand extends DebugPlatformCommand {
    constructor($iOSDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $options) {
        super($iOSDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $options);
    }
}
exports.DebugIOSCommand = DebugIOSCommand;
$injector.registerCommand("debug|ios", DebugIOSCommand);
class DebugAndroidCommand extends DebugPlatformCommand {
    constructor($androidDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $options) {
        super($androidDebugService, $devicesService, $injector, $logger, $childProcess, $devicePlatformsConstants, $config, $usbLiveSyncService, $options);
    }
}
exports.DebugAndroidCommand = DebugAndroidCommand;
$injector.registerCommand("debug|android", DebugAndroidCommand);
