(function(root, factory) {

if (typeof module === 'object' && module.exports) {
    // CommonJS-like environments that support module.exports, like Node.
    module.exports = factory(require('logtown').getLogger('/src/handlers/GetCustomerAccountHandler'), require('../ApiClient'), require('../api/CustomerAccountApi'), require('../OrbipayApiError'), require('../CommonUtil'));
  } 
}(this, function(logger, ApiClient, CustomerAccountApi, OrbipayApiError, CommonUtil) {
  'use strict';

  /**
   * @module ApiClient
   */

  /**
   * <h3 style="color:red"> This class subject to change without prior notice, Please dont use this class directly. </h3>

   * @module handlers/GetCustomerAccountHandler
   * @class
   */

  var exports = function() {
  };

  exports.prototype.process = function (customerAccount, callback) {
        
        var secret = customerAccount.invocation_context.secret;
		var host = customerAccount.api_end_point;
        var api_key = customerAccount.invocation_context.api_key;
        var auth_scheme = customerAccount.invocation_context.auth_scheme;
        var _this=this;
		var response = {};
        var exception;
        try {
            var api_client = new ApiClient(secret, host,api_key,auth_scheme);
			var api_instance = new CustomerAccountApi(api_client);
			var channel = customerAccount.invocation_context['channel'];
			var client_key = customerAccount.invocation_context['client_key'];
			var product = customerAccount.invocation_context['product'];
			var timestamp;
			if (customerAccount.invocation_context['timestamp'])
			{
				timestamp = customerAccount.invocation_context['timestamp'];
			}		
			else
			{
				timestamp = CommonUtil.getTimeStamp();
			}
			var idempotent_request_key = customerAccount.invocation_context['idempotent_request_key'];
			var requestor_type = customerAccount.invocation_context['requestor_type'];
			var id_customer_account = customerAccount['ID_CUSTOMER_ACCOUNT'];
			var id_customer = customerAccount['ID_CUSTOMER'];
            var opts = _this.getOptions(customerAccount);
			var result = api_instance.getCustomerAccount(channel, client_key, product, timestamp, idempotent_request_key, requestor_type, id_customer_account, id_customer,  opts, callback);
			response['request'] = result;
			return response;
        } catch (e) {
            exception = OrbipayApiError.getDefaultException(e);
            if (callback) {
                callback(null, null, null, exception);
            }
            response['exception'] = exception;
            return response;
        }
    };

    exports.prototype.getOptions = function (customerAccount) {
        return {
		    'requestor': customerAccount['invocation_context']['requestor'], 
		    'x_opay_headers': customerAccount['invocation_context']['X-OPAY-Headers']
        };
    };  


  return exports;
}));