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 __());
};
/// <reference path="../base/BaseClass.ts" />
/// <reference path="./IVariableConfigOptions.ts" />
/// <reference path="../serialization/ISerializable.ts" />
var econda;
(function (econda) {
    var storage;
    (function (storage) {
        /**
         * Data Variable
         * @experimental
         * @class econda.storage.Variable
         */
        var Variable = (function (_super) {
            __extends(Variable, _super);
            function Variable(cfg) {
                _super.call(this);
                /**
                 * Name of variable.
                 * @cfg {String} name
                 * @accessor
                 */
                this._name = null;
                /**
                 * Variable value.
                 * @cfg {Mixed} value
                 * @accessor
                 */
                this._value = null;
                /**
                 * Set to true to store the data in browsers local storage object. If set to false (default), we'll store it in browsers session storage
                 * so it will be destroyed at end of session.
                 * @cfg {Boolean} permanent
                 * @accessor
                 */
                this._permanent = false;
                /**
                 * Number of page views after which this variable will be destroyed
                 * @cfg {Number} pageViewsToLive
                 * @accessor
                 */
                this._pageViewsToLive = null;
                /**
                 * Date when this variable will be destoryed
                 * @cfg {Date} expires
                 */
                this._expires = null;
                /**
                 * Action to performe when variable expires
                 * @cfg {String} invalidationAction
                 */
                this._invalidationAction = Variable.INVALIDATION_ACTION_REMOVE;
                this._isValid = true;
                if (cfg instanceof Variable) {
                    return cfg;
                }
                this.initConfig(cfg);
            }
            Variable.prototype.setName = function (name) {
                this._name = name;
                return this;
            };
            Variable.prototype.getName = function () {
                return this._name;
            };
            Variable.prototype.setValue = function (data) {
                this._value = data;
                return this;
            };
            Variable.prototype.getValue = function () {
                return this._value;
            };
            Variable.prototype.setPermanent = function (permanent) {
                this._permanent = permanent;
                return this;
            };
            Variable.prototype.getPermanent = function () {
                return this._permanent;
            };
            Variable.prototype.setPageViewsToLive = function (numberOfPageViews) {
                this._pageViewsToLive = numberOfPageViews;
                return this;
            };
            Variable.prototype.getPageViewsToLive = function () {
                return this._pageViewsToLive;
            };
            Variable.prototype.setExpires = function (date) {
                this._expires = date;
                return this;
            };
            Variable.prototype.getExpires = function () {
                return this._expires;
            };
            /**
             * Set expires property to date object given number of seconds from now.
             * @param {Number} seconds
             * @chainable
             */
            Variable.prototype.setTtl = function (seconds) {
                var d = new Date();
                d.setSeconds(d.getSeconds() + seconds);
                this._expires = d;
                return this;
            };
            Variable.prototype.setInvalidationAction = function (action) {
                this._invalidationAction = action;
                return this;
            };
            Variable.prototype.getInvalidationAction = function () {
                return this._invalidationAction;
            };
            /**
             * Returns false if variable is invalid. Only variable with invalidationAction = 'keep' will be hold in
             * a bag.
             * @returns {Boolean}
             */
            Variable.prototype.getIsValid = function () {
                return this._isValid;
            };
            /**
             * Set if variable is valid or not. Should be done by ClientBag only.
             * @protected
             */
            Variable.prototype._setIsValid = function (isValid) {
                this._isValid = isValid;
                return this;
            };
            /**
             * Get serialization info.
             */
            Variable.prototype.getObjectData = function () {
                var ret = {
                    className: 'econda.storage.Variable',
                    data: {
                        name: this._name,
                        value: this._value,
                        expires: this._expires,
                        pageViewsToLive: this._pageViewsToLive,
                        permanent: this._permanent,
                        invalidationAction: this._invalidationAction
                    }
                };
                return ret;
            };
            /**
             * Set object data on deserialization
             */
            Variable.prototype.setObjectData = function (data) {
                this.set(data);
            };
            /**
             * Remove variable when invalid
             * @property
             * @static
             */
            Variable.INVALIDATION_ACTION_REMOVE = 'remove';
            /**
             * Keep variable in bag even if invalid
             * @property
             * @static
             */
            Variable.INVALIDATION_ACTION_KEEP = 'keep';
            return Variable;
        }(econda.base.BaseClass));
        storage.Variable = Variable;
    })(storage = econda.storage || (econda.storage = {}));
})(econda || (econda = {}));