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

  var exports = function() {
  };

  exports.prototype.process = function (paymentSetups, callback) {
        
        var secret = paymentSetups.invocation_context.secret;
		var host = paymentSetups.api_end_point;
        var api_key = paymentSetups.invocation_context.api_key;
        var auth_scheme = paymentSetups.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 PaymentSetupApi(api_client);
			var channel = paymentSetups.invocation_context['channel'];
			var client_key = paymentSetups.invocation_context['client_key'];
			var product = paymentSetups.invocation_context['product'];
			var timestamp;
			if (paymentSetups.invocation_context['timestamp'])
			{
				timestamp = paymentSetups.invocation_context['timestamp'];
			}		
			else
			{
				timestamp = CommonUtil.getTimeStamp();
			}
			var idempotent_request_key = paymentSetups.invocation_context['idempotent_request_key'];
			var requestor_type = paymentSetups.invocation_context['requestor_type'];
            var opts = _this.getOptions(paymentSetups);
			var result = api_instance.retrievePaymentSetups(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 (paymentSetups) {
        return {
		    'requestor': paymentSetups['invocation_context']['requestor'], 
		    'x_opay_headers': paymentSetups['invocation_context']['X-OPAY-Headers'], 
		    'id_customer': paymentSetups['id_customer'], 
		    'id_funding_account': paymentSetups['id_funding_account'], 
		    'id_customer_account': paymentSetups['id_customer_account'], 
		    'confirmation_number': paymentSetups['confirmation_number'], 
		    'status': paymentSetups['status'], 
		    'payment_setup_schedule_type': paymentSetups['payment_setup_schedule_type'], 
		    'from_date': paymentSetups['from_date'], 
		    'to_date': paymentSetups['to_date'], 
		    'page_size': paymentSetups['page_size'], 
		    'query_id': paymentSetups['query_id'], 
		    'from_index': paymentSetups['from_index'], 
		    'to_index': paymentSetups['to_index']
        };
    };  


  return exports;
}));