var uniflash;
(function (uniflash) {
    var session;
    (function (session) {
        'use strict';
        var SessionDataStore = (function () {
            function SessionDataStore() {
                this.sessionData = {};
                this.sessionDataProviders = {};
            }
            // key - to store the data based on
            // provider - {
            //		onSessionLoad, - Called when a new session is loaded; could be loaded from file or completely new
            //      getSessionData - Called before the sesison is save; so the provider could provide data	
            //	}
            SessionDataStore.prototype.registerSessionDataProvider = function (key, provider) {
                if (this.sessionDataProviders[key])
                    throw 'Session data provider ' + key + ' already exists';
                this.sessionDataProviders[key] = provider;
                // since services are lazy loaded in angular
                // the session may have been loaded without a service being yet initialized
                // thus, we call it once right away so it could initialize it self properly
                this.sendDataToProvider(key, provider);
            };
            SessionDataStore.prototype.sendDataToProvider = function (key, provider) {
                return provider.onSessionLoad(this.sessionData[key]);
            };
            // a different session has been loaded
            SessionDataStore.prototype.sessionLoaded = function () {
                var _this = this;
                _.each(this.sessionDataProviders, function (provider, key) {
                    _this.sendDataToProvider(key, provider);
                });
            };
            SessionDataStore.prototype.updateBeforeSave = function () {
                var _this = this;
                _.each(this.sessionDataProviders, function (provider, key) {
                    _this.sessionData[key] = provider.getSessionData();
                });
            };
            SessionDataStore.prototype.getSessionDataAll = function () {
                return this.sessionData;
            };
            SessionDataStore.prototype.setSessionDataAll = function (data) {
                this.sessionData = data;
            };
            return SessionDataStore;
        }());
        session.SessionDataStore = SessionDataStore;
    })(session = uniflash.session || (uniflash.session = {}));
})(uniflash || (uniflash = {}));
