(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/RetrieveCustomersHandler'), require('../ApiClient'), require('../api/CustomerApi'), require('../OrbipayApiError'), require('../CommonUtil'));
  } 
}(this, function(logger, ApiClient, CustomerApi, 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/RetrieveCustomersHandler
   * @class
   */

  var exports = function() {
  };

  exports.prototype.process = function (customers, callback) {
        
        var secret = customers.invocation_context.secret;
		var host = customers.api_end_point;
        var api_key = customers.invocation_context.api_key;
        var auth_scheme = customers.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 CustomerApi(api_client);
			var channel = customers.invocation_context['channel'];
			var client_key = customers.invocation_context['client_key'];
			var product = customers.invocation_context['product'];
			var timestamp;
			if (customers.invocation_context['timestamp'])
			{
				timestamp = customers.invocation_context['timestamp'];
			}		
			else
			{
				timestamp = CommonUtil.getTimeStamp();
			}
			var idempotent_request_key = customers.invocation_context['idempotent_request_key'];
			var requestor_type = customers.invocation_context['requestor_type'];
            var opts = _this.getOptions(customers);
			var result = api_instance.retrieveCustomers(channel, client_key, product, timestamp, idempotent_request_key, requestor_type,  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 (customers) {
        return {
		    'requestor': customers['invocation_context']['requestor'], 
		    'x_opay_headers': customers['invocation_context']['X-OPAY-Headers'], 
		    'page_size': customers['page_size'], 
		    'customer_reference': customers['customer_reference'], 
		    'ssn': customers['ssn'], 
		    'email': customers['email'], 
		    'account_number': customers['account_number']
        };
    };  


  return exports;
}));