var _ = require('../util').lodash,
    PropertyBase = require('./property-base').PropertyBase,

    RequestAuthBase;

_.inherit((

    /**
     * A Postman Request Auth State, which is in charge of holding the intermediate parameters for
     * the supported auth mechanisms.
     *
     * @param {Object} state
     * @constructor
     * @extends {PropertyBase}
     */
    RequestAuthBase = function PostmanRequestAuthHandler (state) {
        // this constructor is intended to inherit and as such the super constructor is required to be executed
        RequestAuthBase.super_.call(this, arguments);

        _.assign(this, /** @lends RequestAuthBase.prototype */ {
            /**
             * Holds intermediate state for all authorizations.
             *
             * @type {Object}
             */
            state: state || {}
        });
    }), PropertyBase);

_.extend(RequestAuthBase.prototype, /** @lends RequestAuthState.prototype */ {

    /**
     * Sets a value in the state.
     *
     * @param name
     * @param value
     */
    set: function (name, value) {
        name && (this.state[name] = value);
    },

    /**
     * Gets the value of a parameter from the state.
     *
     * @param name
     */
    get: function (name) {
        return this.state[name];
    },

    /**
     * Sets multiple names and values in one go.
     *
     * @param {Object} values
     */
    update: function (values) {
        if (!_.isObject(values)) { return; }

        var key;

        for (key in values) {
            values.hasOwnProperty(key) && this.set(key, values[key]);
        }
    },

    /**
     * Override the default toJSON functionality so that we don't accidentally leak state.
     *
     * @returns {Object}
     */
    toJSON: function () {
        var obj = PropertyBase.toJSON(this);

        // faster than omit, and we've already created a new object, so no point doing it.
        obj.state && delete obj.state;

        return obj;
    }
});

_.extend(RequestAuthBase, /** @lends RequestAuthBase */ {

    /**
     * @type {String}
     */
    _postman_propertyName: 'RequestAuthBase'
});

module.exports.RequestAuthBase = RequestAuthBase;

@@ -422,16 +422,22 @@
 andler (
+name, 
 state) %7B
@@ -669,16 +669,152 @@
 pe */ %7B%0A
+%0A            /**%0A             * Name of the auth.%0A             *%0A             * @type %7BString%7D%0A             */%0A            name: name,%0A%0A
         
@@ -2116,16 +2116,195 @@
 rn obj;%0A
+    %7D,%0A%0A    /**%0A     * String representation of this auth.%0A     *%0A     * @returns %7BString%7D%0A     */%0A    toString: function () %7B%0A        return _.invoke(this, 'name.toString', '');%0A
     %7D%0A%7D)

allow request auth base to have a name