"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    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) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AndroidLiveSyncService = void 0;
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 decorators_1 = require("../../common/decorators");
const semver = require("semver");
const _ = require("lodash");
const yok_1 = require("../../common/yok");
class AndroidLiveSyncService extends platform_livesync_service_base_1.PlatformLiveSyncServiceBase {
    constructor($platformsDataService, $projectFilesManager, $injector, $devicePathProvider, $fs, $logger, $options) {
        super($fs, $logger, $platformsDataService, $projectFilesManager, $devicePathProvider, $options);
        this.$platformsDataService = $platformsDataService;
        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 = Object.create(null, {
            liveSyncWatchAction: { get: () => super.liveSyncWatchAction }
        });
        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 = Object.create(null, {
            fullSync: { get: () => super.fullSync }
        });
        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;
        });
    }
    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";
__decorate([
    (0, decorators_1.performanceLog)()
], AndroidLiveSyncService.prototype, "liveSyncWatchAction", null);
__decorate([
    (0, decorators_1.performanceLog)()
], AndroidLiveSyncService.prototype, "fullSync", null);
exports.AndroidLiveSyncService = AndroidLiveSyncService;
yok_1.injector.register("androidLiveSyncService", AndroidLiveSyncService);
//# sourceMappingURL=android-livesync-service.js.map