"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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const android_device_livesync_service_1 = require("./android-device-livesync-service");
const android_device_livesync_sockets_service_1 = require("./android-device-livesync-sockets-service");
const platform_livesync_service_base_1 = require("./platform-livesync-service-base");
const semver = require("semver");
class AndroidLiveSyncService extends platform_livesync_service_base_1.PlatformLiveSyncServiceBase {
    constructor($platformsData, $projectFilesManager, $injector, $devicePathProvider, $fs, $logger, $projectFilesProvider) {
        super($fs, $logger, $platformsData, $projectFilesManager, $devicePathProvider, $projectFilesProvider);
        this.$platformsData = $platformsData;
        this.$projectFilesManager = $projectFilesManager;
        this.$injector = $injector;
    }
    _getDeviceLiveSyncService(device, data, frameworkVersion) {
        if (semver.gt(frameworkVersion, AndroidLiveSyncService.MIN_SOCKETS_LIVESYNC_RUNTIME_VERSION)) {
            return this.$injector.resolve(android_device_livesync_sockets_service_1.AndroidDeviceSocketsLiveSyncService, { device, data });
        }
        return this.$injector.resolve(android_device_livesync_service_1.AndroidDeviceLiveSyncService, { device, data });
    }
    liveSyncWatchAction(device, liveSyncInfo) {
        const _super = name => super[name];
        return __awaiter(this, void 0, void 0, function* () {
            const liveSyncResult = yield _super("liveSyncWatchAction").call(this, device, liveSyncInfo);
            const result = yield this.finalizeSync(device, liveSyncInfo.projectData, liveSyncResult);
            return result;
        });
    }
    fullSync(syncInfo) {
        const _super = name => super[name];
        return __awaiter(this, void 0, void 0, function* () {
            const liveSyncResult = yield _super("fullSync").call(this, syncInfo);
            const result = yield this.finalizeSync(syncInfo.device, syncInfo.projectData, liveSyncResult);
            return result;
        });
    }
    prepareForLiveSync(device, data) {
        return __awaiter(this, void 0, void 0, function* () { });
    }
    finalizeSync(device, projectData, liveSyncResult) {
        return __awaiter(this, void 0, void 0, function* () {
            const liveSyncService = this.getDeviceLiveSyncService(device, projectData);
            const finalizeResult = yield liveSyncService.finalizeSync(liveSyncResult, projectData);
            const result = _.extend(liveSyncResult, finalizeResult);
            return result;
        });
    }
}
AndroidLiveSyncService.MIN_SOCKETS_LIVESYNC_RUNTIME_VERSION = "4.2.0-2018-07-20-02";
exports.AndroidLiveSyncService = AndroidLiveSyncService;
$injector.register("androidLiveSyncService", AndroidLiveSyncService);
