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="./ZeroGapUtil.ts"/>
var econda;
(function (econda) {
    var base;
    (function (base) {
        var ZeroGapUtil = econda.util.ZeroGapUtil;
        /**
         * Request context, e.g. the product we want to get recommendations for.
         * @class econda.base.BaseContext
         * @extends econda.base.BaseClass
         *
         */
        var BaseContext = (function (_super) {
            __extends(BaseContext, _super);
            function BaseContext() {
                _super.apply(this, arguments);
                this.profileProperties = {};
                /**
                 * econda visitor id
                 * @cfg {String} visitorId
                 * @accessor
                 */
                this.visitorId = null;
                /**
                 * econda session id
                 * @cfg {String} sessionId
                 * @accessor
                 */
                this.sessionId = null;
                /**
                 * econda customer id
                 * @cfg {String} customerId
                 * @accessor
                 */
                this.customerId = null;
                /**
                 * econda recipient id
                 * @cfg {String} recipientId
                 * @accessor
                 */
                this.recipientId = null;
                /**
                 * econda user id
                 * @cfg {String} userId
                 * @accessor
                 */
                this.userId = null;
                /**
                 * econda email
                 * @cfg {String} email
                 * @accessor
                 */
                this.email = null;
                /**
                 * econda emailHash
                 * @cfg {String} emailHash
                 * @accessor
                 */
                this.emailHash = null;
            }
            BaseContext.prototype.setProfileProperties = function (profileProperties) {
                this.profileProperties = profileProperties;
            };
            BaseContext.prototype.getProfileProperties = function () {
                return this.profileProperties;
            };
            BaseContext.prototype.setVisitorId = function (visitorId) {
                this.visitorId = visitorId;
                return this;
            };
            BaseContext.prototype.getVisitorId = function () {
                return this.visitorId;
            };
            BaseContext.prototype.setSessionId = function (sessionId) {
                this.sessionId = sessionId;
                return this;
            };
            BaseContext.prototype.getSessionId = function () {
                return this.sessionId;
            };
            BaseContext.prototype.setCustomerId = function (customerId) {
                this.customerId = customerId;
                return this;
            };
            BaseContext.prototype.getCustomerId = function () {
                return this.customerId;
            };
            BaseContext.prototype.setRecipientId = function (recipientId) {
                this.recipientId = recipientId;
                return this;
            };
            BaseContext.prototype.getRecipientId = function () {
                return this.recipientId;
            };
            BaseContext.prototype.setUserId = function (userId) {
                this.userId = userId;
                return this;
            };
            BaseContext.prototype.getUserId = function () {
                return this.userId;
            };
            BaseContext.prototype.setEmail = function (email) {
                this.email = email;
                return this;
            };
            BaseContext.prototype.getEmail = function () {
                return this.email;
            };
            BaseContext.prototype.setEmailHash = function (emailHash) {
                this.emailHash = emailHash;
                return this;
            };
            BaseContext.prototype.getEmailHash = function () {
                return this.emailHash;
            };
            BaseContext.prototype.addToRequest = function (params) {
                // visitor information
                if (this.getVisitorId()) {
                    params['emvid'] = this.getVisitorId();
                }
                if (this.getSessionId()) {
                    params['emsid'] = this.getSessionId();
                }
                if (this.getCustomerId()) {
                    params['emcid'] = this.getCustomerId();
                }
                if (this.getRecipientId()) {
                    params['emrid'] = this.getRecipientId();
                }
                if (this.getUserId()) {
                    params['emuid'] = this.getUserId();
                }
                if (this.getEmail()) {
                    params['ememail'] = this.getEmail();
                }
                if (this.getEmailHash()) {
                    params['ememailhash'] = this.getEmailHash();
                }
                // get visitor profile properties from context and prefix property key with "p."
                if (window['econda']['arp']) {
                    // fill from arp
                    var profile = window['econda']['arp']['ZeroGap'].getProfile();
                    delete profile.timestamp;
                    delete profile.emvid;
                    for (var key in profile) {
                        if (profile.hasOwnProperty(key)) {
                            params[key] = econda.util.Json.stringify(profile[key]);
                        }
                    }
                }
                else {
                    // fill it the classic way without arp
                    ZeroGapUtil.appendProfileProperties(params, this.getProfileProperties());
                }
            };
            return BaseContext;
        }(econda.base.BaseClass));
        base.BaseContext = BaseContext; // end of class
    })(base = econda.base || (econda.base = {}));
})(econda || (econda = {})); // end of module