"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RunApplicationOnDeviceCommand = void 0;
const yok_1 = require("../../yok");
class RunApplicationOnDeviceCommand {
    constructor($devicesService, $errors, $stringParameter, $staticConfig, $options) {
        this.$devicesService = $devicesService;
        this.$errors = $errors;
        this.$stringParameter = $stringParameter;
        this.$staticConfig = $staticConfig;
        this.$options = $options;
        this.allowedParameters = [
            this.$stringParameter,
            this.$stringParameter,
        ];
    }
    async execute(args) {
        await this.$devicesService.initialize({
            deviceId: this.$options.device,
            skipInferPlatform: true,
        });
        if (this.$devicesService.deviceCount > 1) {
            this.$errors.failWithHelp("More than one device found. Specify device explicitly with --device option. To discover device ID, use $%s device command.", this.$staticConfig.CLIENT_NAME.toLowerCase());
        }
        await this.$devicesService.execute(async (device) => await device.applicationManager.startApplication({
            appId: args[0],
            projectName: args[1],
            projectDir: null,
        }));
    }
}
exports.RunApplicationOnDeviceCommand = RunApplicationOnDeviceCommand;
yok_1.injector.registerCommand(["device|run", "devices|run"], RunApplicationOnDeviceCommand);
