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="proxy/WebtokenEndpointProxy.ts" />
/// <reference path="Request.ts" />
var econda;
(function (econda) {
    var profileaccess;
    (function (profileaccess) {
        /**
         * A profile endpoint request with webtoken based authentication.
         *
         * The webtoken has to created on the 'server' before sending this endpoint request.
         * The used id values should not be exposed to the client.
         *
         * @class econda.profileaccess.WebTokenEndpointRequest
         * @extends econda.profileaccess.Request
         *
         * <h2>Examples</h2>
         *
         * <h3>Send an endpoint request where the userId is 'baked' into a webToken.</h3>
         * <pre><code>
         * // The endpoint has to be configured in the econda personalisation interface.
         *
         * // The endpointKey is the unique identifier for this endpoint.
         *
         * // We send the request in a callback of the async webtoken function (see below).
         * var sendWebTokenEndpointRequest = function(webToken) {
         *
         *       var request = new econda.profileaccess.WebTokenEndpointRequest({
         *           accountId: '00000cec-d98025a8-912b-46a4-a57d-7a691ba7a376',
         *           endpointKey: 'webtoken',
         *           webToken: webToken,
         *           success: function(profile) {
         *               // Profile is an object containing all returned properties as key value pairs.
         *               //
         *               // Example:
         *               //      profile = {
         *               //          gender: 'male'
         *               //      }
         *               //
         *               showProfileData(profile);
         *           },
         *           error: function(error) {
         *               // Error object
         *               handleError(error);
         *           }
         *       });
         *       request.send();
         *   };
         *
         * // Call your server and create a webtoken with id values only known to the server as claims
         * // signed with a passphrase as configured in endpoint configuration in the econda personalisation interface.
         * //
         * // On successful return of the webtoken send the webtoken endpoint request (see above).
         * createWebTokenOnServerAndSendEndpointRequest(sendWebTokenEndpointRequest);
         * </code></pre>
         */
        var WebTokenEndpointRequest = (function (_super) {
            __extends(WebTokenEndpointRequest, _super);
            function WebTokenEndpointRequest(cfg) {
                if (cfg === void 0) { cfg = null; }
                _super.call(this);
                /**
                 * The webToken used for authenication.
                 *
                 * This has be created on the 'server' before sending this endpoint request.
                 *
                 * The token contains the profile id(s) as claim and will be signed with a keyphrase
                 * as defined in the corresponding endpoint configuration.
                 *
                 * The id is most likely a userId.
                 *
                 * The id keys have to be in their server side representation
                 * <pre><code>
                 * - emvid       econda tracking visitor id
                 * - emcid       econda tracking customer id
                 * - emrid       econda tracking recipient id
                 * - emuid       econda tracking user id
                 * - ememail     email address
                 * - ememailhash hashed email address
                 * - emprofileid profile id
                 * </code></pre>
                 * @cfg {String} webToken
                 */
                this.webToken = null;
                if (cfg instanceof WebTokenEndpointRequest) {
                    return cfg;
                }
                this.initConfig(cfg);
                if (!this.getProxy()) {
                    this.setProxy(new econda.profileaccess.proxy.WebtokenEndpointProxy());
                }
            }
            /**
             * Returns the webToken to be used for authentication.
             * @returns String
             */
            WebTokenEndpointRequest.prototype.getWebToken = function () {
                return this.webToken;
            };
            /**
             * Set account the webToken for this request.
             * @param {String} webToken
             * @chainable
             */
            WebTokenEndpointRequest.prototype.setWebToken = function (webToken) {
                this.webToken = webToken;
                return this;
            };
            WebTokenEndpointRequest.prototype._validateAndLogErrors = function () {
                _super.prototype._validateAndLogErrors.call(this);
                if (!this.getWebToken()) {
                    econda.debug.error('Missing webtoken in request', this);
                }
            };
            return WebTokenEndpointRequest;
        }(profileaccess.Request));
        profileaccess.WebTokenEndpointRequest = WebTokenEndpointRequest;
    })(profileaccess = econda.profileaccess || (econda.profileaccess = {}));
})(econda || (econda = {}));