"use strict";
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var events_1 = require("events");
var ApplicationManagerBase = (function (_super) {
    __extends(ApplicationManagerBase, _super);
    function ApplicationManagerBase() {
        _super.apply(this, arguments);
    }
    ApplicationManagerBase.prototype.reinstallApplication = function (appIdentifier, packageFilePath) {
        var _this = this;
        return (function () {
            _this.uninstallApplication(appIdentifier).wait();
            _this.installApplication(packageFilePath).wait();
        }).future()();
    };
    ApplicationManagerBase.prototype.restartApplication = function (appIdentifier, bundleExecutable) {
        var _this = this;
        return (function () {
            _this.stopApplication(bundleExecutable || appIdentifier).wait();
            _this.startApplication(appIdentifier).wait();
        }).future()();
    };
    ApplicationManagerBase.prototype.isApplicationInstalled = function (appIdentifier) {
        var _this = this;
        return (function () {
            var installedApplications = _this.getInstalledApplications().wait();
            return _.contains(installedApplications, appIdentifier);
        }).future()();
    };
    ApplicationManagerBase.prototype.checkForApplicationUpdates = function () {
        var _this = this;
        return (function () {
            var newInstalledApplications = _this.getInstalledApplications().wait();
            var previouslyInstalledApplications = _this.lastInstalledApplications || [];
            _(newInstalledApplications)
                .difference(previouslyInstalledApplications)
                .each(function (application) { return _this.emit("applicationInstalled", application); })
                .value();
            _(previouslyInstalledApplications)
                .difference(newInstalledApplications)
                .each(function (application) { return _this.emit("applicationUninstalled", application); })
                .value();
            _this.lastInstalledApplications = newInstalledApplications;
        }).future()();
    };
    return ApplicationManagerBase;
})(events_1.EventEmitter);
exports.ApplicationManagerBase = ApplicationManagerBase;
