"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeployController = void 0;
const _ = require("lodash");
const yok_1 = require("../common/yok");
class DeployController {
    constructor($deviceInstallAppService, $devicesService, $prepareController) {
        this.$deviceInstallAppService = $deviceInstallAppService;
        this.$devicesService = $devicesService;
        this.$prepareController = $prepareController;
    }
    async deploy(data) {
        const { deviceDescriptors } = data;
        const executeAction = async (device) => {
            const deviceDescriptor = _.find(deviceDescriptors, (dd) => dd.identifier === device.deviceInfo.identifier);
            const prepareData = {
                ...deviceDescriptor.buildData,
                nativePrepare: {
                    skipNativePrepare: !!deviceDescriptor.skipNativePrepare,
                },
            };
            await this.$prepareController.prepare(prepareData);
            const packageFilePath = await deviceDescriptor.buildAction();
            await this.$deviceInstallAppService.installOnDevice(device, { ...deviceDescriptor.buildData, buildForDevice: !device.isEmulator }, packageFilePath);
        };
        await this.$devicesService.execute(executeAction, (device) => _.some(deviceDescriptors, (deviceDescriptor) => deviceDescriptor.identifier === device.deviceInfo.identifier));
    }
}
exports.DeployController = DeployController;
yok_1.injector.register("deployController", DeployController);
