"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LiveSyncProcessDataService = void 0;
const yok_1 = require("../common/yok");
const _ = require("lodash");
class LiveSyncProcessDataService {
    constructor() {
        this.processes = {};
    }
    persistData(projectDir, deviceDescriptors, platforms) {
        this.processes[projectDir] =
            this.processes[projectDir] || Object.create(null);
        this.processes[projectDir].actionsChain =
            this.processes[projectDir].actionsChain || Promise.resolve();
        this.processes[projectDir].currentSyncAction = this.processes[projectDir].actionsChain;
        this.processes[projectDir].isStopped = false;
        this.processes[projectDir].platforms = platforms;
        const currentDeviceDescriptors = this.getDeviceDescriptors(projectDir);
        this.processes[projectDir].deviceDescriptors = _.uniqBy(currentDeviceDescriptors.concat(deviceDescriptors), "identifier");
    }
    getPersistedData(projectDir) {
        return this.processes[projectDir];
    }
    getDeviceDescriptors(projectDir) {
        const liveSyncProcessesInfo = this.processes[projectDir] || {};
        const currentDescriptors = liveSyncProcessesInfo.deviceDescriptors;
        return currentDescriptors || [];
    }
    hasDeviceDescriptors(projectDir) {
        const deviceDescriptors = this.getDeviceDescriptors(projectDir);
        return !!deviceDescriptors.length;
    }
    getAllPersistedData() {
        return this.processes;
    }
    getPlatforms(projectDir) {
        const liveSyncProcessesInfo = this.processes[projectDir] || {};
        const currentPlatforms = liveSyncProcessesInfo.platforms;
        return currentPlatforms || [];
    }
}
exports.LiveSyncProcessDataService = LiveSyncProcessDataService;
yok_1.injector.register("liveSyncProcessDataService", LiveSyncProcessDataService);
//# sourceMappingURL=livesync-process-data-service.js.map