(function(root, factory) {

if (typeof module === 'object' && module.exports) {
    // CommonJS-like environments that support module.exports, like Node.
    module.exports = factory(require('logtown').getLogger('orbipay-paymentsapi-client/src/wrappers/Base'), require('./InvocationContext'), require('../CommonUtil'));
  } 
}(this, function(logger, InvocationContext, CommonUtil) {
  'use strict';

  var exports = function() {
  };

  exports.constructFromObject = function (data, obj) {
        if (data) {
            obj = obj || new exports();
            if (data.hasOwnProperty('invocation_context')) {
                obj['invocation_context'] = InvocationContext.constructFromObject(data['invocation_context']);
            }
            if (data.hasOwnProperty('api_end_point')) {
                obj['api_end_point'] = data['api_end_point'];
            }
        }
        return obj;
    };

    /**
     * @member {String} invocation_context
     */
    exports.prototype['invocation_context'] = undefined;
    /**
     * @member {String} api_end_point
     */
    exports.prototype['api_end_point'] = undefined;
    /**
     * @member {String} http_status_code
     */
    exports.prototype['http_status_code'] = undefined;

    /**
     * @private
     * @param {String} requestor
     * @param {String} requestor_type
     * @return module:model/customer/Customer
     */
    exports.prototype.requestedBy = function (requestor, requestor_type) {
        var _this = this;
        if (!CommonUtil.isNonEmptyObject(_this['invocation_context'])) {
            _this['invocation_context'] = new InvocationContext();

        }
        _this['invocation_context']['requestor'] = requestor;
        _this['invocation_context']['requestor_type'] = requestor_type;
    };


    /**
     * @param {String} channel
     * @return module:model/customer/Customer
     */
    exports.prototype.videChannel = function (channel) {
        var _this = this;
        if (!CommonUtil.isNonEmptyObject(_this['invocation_context'])) {
            _this['invocation_context'] = new InvocationContext();

        }
        _this['invocation_context']['channel'] = channel;
    };

    /**
     * @param {String} client_key
     * @return module:model/customer/Customer
     */
    exports.prototype.forClient = function (client_key) {
        var _this = this;
        if (!CommonUtil.isNonEmptyObject(_this['invocation_context'])) {
            _this['invocation_context'] = new InvocationContext();
        }
        _this['invocation_context']['client_key'] = client_key;
    };

    /**
     * @private
     * @param {String} live_mode.
     * @param {String} api_end_point. For example http://localhost:8080/payments/v1
     */
    exports.prototype.setAPIEndPoint = function (live_mode, api_end_point) {
        var _this = this;
		if (live_mode === 'true') {
            _this['api_end_point'] = 'https://api.orbipay.com/payments/v1';
        }
        else if (live_mode === 'false' && !api_end_point) {
            _this['api_end_point'] = 'https://sbapi.orbipay.com/payments/v1';
        }
        else if(live_mode === 'false' && api_end_point){
            _this['api_end_point'] = api_end_point;
        }
        else{
            logger.error('Invalid value for live_mode,  value Received in request :'+ live_mode +', valid values for live_mode: true, false');
            throw new Error('Invalid value for live_mode,  value Received in request :'+ live_mode +', valid values for live_mode: true, false');
        }
    };

    /**
     * @private
     * @param {module:model/base/InvocationContext} invocation_context
     * @param {String} live_mode.
     * @param {String} api_end_point. For example http://localhost:8080/payments/v1
     * @return module:model/customer/Customer
     */
    exports.prototype.withContext = function (invocation_context, live_mode, api_end_point) {
        var _this = this;
        _this.setAPIEndPoint(live_mode, api_end_point);
        if (!CommonUtil.isNonEmptyObject(_this['invocation_context'])) {
            _this['invocation_context'] = new InvocationContext();
        }

        if (invocation_context) {
            logger.info('idempotent_request_key :', invocation_context['idempotent_request_key']);
            _this['invocation_context']['X-OPAY-Headers'] = invocation_context['X-OPAY-Headers'];
            _this['invocation_context']['idempotent_request_key'] = invocation_context['idempotent_request_key'];
            _this['invocation_context']['product'] = invocation_context['product'];
            _this['invocation_context']['api_key'] = invocation_context['api_key'];
            _this['invocation_context']['auth_scheme'] = invocation_context['auth_scheme'];
            if(invocation_context['secret']){
                _this['invocation_context']['secret'] = invocation_context['secret'];
            }
            else{
                throw new Error('Invalid value for secret');
            }
        }
    };

  return exports;

}));