(function(root, factory) {

if (typeof module === 'object' && module.exports) {
    // CommonJS-like environments that support module.exports, like Node.
    module.exports = factory(require('../ApiClient'), require('./InvocationContext'), require('../CommonUtil'), require('../ResponseWrapper'), require('./Base')
, require('../handlers/RetrievePaymentsHandler'), require('../OrbipayApiError'));
  }
}(this, function(ApiClient, InvocationContext, CommonUtil, ResponseWrapper, Base, RetrievePaymentsHandler, OrbipayApiError) {
  'use strict';

    /**
    * The Payments wrapper module.
    * @module wrappers/Payments
    */
  var exports = function() {

  };
  exports.constructFromObject = function (data, obj) {
        if (data) {
            obj = obj || new exports();
            if (data.hasOwnProperty('list')) {
		var Payment = require('./Payment');
                obj['list'] = ApiClient.convertToType(data['list'], [Payment]);
            }
            if (data.hasOwnProperty('total_results_count')) {
                obj['total_results_count'] = data['total_results_count'];
            }
            if (data.hasOwnProperty('has_more_results')) {
                obj['has_more_results'] = data['has_more_results'];
            }
            if (data.hasOwnProperty('url')) {
                obj['url'] = data['url'];
            }
            if (data.hasOwnProperty('from_index')) {
                obj['from_index'] = data['from_index'];
            }
            if (data.hasOwnProperty('to_index')) {
                obj['to_index'] = data['to_index'];
            }
            if (data.hasOwnProperty('query_id')) {
                obj['query_id'] = data['query_id'];
            }
            if (data.hasOwnProperty('id_customer')) {
                obj['id_customer'] = data['id_customer'];
            }
            if (data.hasOwnProperty('id_funding_account')) {
                obj['id_funding_account'] = data['id_funding_account'];
            }
            if (data.hasOwnProperty('id_customer_account')) {
                obj['id_customer_account'] = data['id_customer_account'];
            }
            if (data.hasOwnProperty('confirmation_number')) {
                obj['confirmation_number'] = data['confirmation_number'];
            }
            if (data.hasOwnProperty('status')) {
                obj['status'] = data['status'];
            }
            if (data.hasOwnProperty('payment_schedule_type')) {
                obj['payment_schedule_type'] = data['payment_schedule_type'];
            }
            if (data.hasOwnProperty('payment_method')) {
                obj['payment_method'] = data['payment_method'];
            }
            if (data.hasOwnProperty('from_date')) {
                obj['from_date'] = data['from_date'];
            }
            if (data.hasOwnProperty('to_date')) {
                obj['to_date'] = data['to_date'];
            }
            if (data.hasOwnProperty('page_size')) {
                obj['page_size'] = data['page_size'];
            }
        }
        return obj;
  };


  exports.prototype = Object.create(Base.prototype);
  exports.prototype.constructor = exports;

    /**
    * @member [Payment] list
    */
  exports.prototype['list'] = undefined;
    /**
    * total number of payments available with matching criteria
    * @member {String} total_results_count
    */
  exports.prototype['total_results_count'] = undefined;
    /**
    * true if there are more results or pages
    * @member {String} has_more_results
    */
  exports.prototype['has_more_results'] = undefined;
    /**
    * This URL fetches the next or previous set of payments, based on the presence of after_object or before_object parameter.
    * @member {String} url
    */
  exports.prototype['url'] = undefined;
    /**
    * The id of the object before which the previous set of objects are to be retrieved.
    * @member {String} from_index
    */
  exports.prototype['from_index'] = undefined;
    /**
    * The id of the object after which the next set of objects are to be retrieved.
    * @member {String} to_index
    */
  exports.prototype['to_index'] = undefined;
    /**
    * The query id of the object.
    * @member {String} query_id
    */
  exports.prototype['query_id'] = undefined;
    /**
    * The unique identifier assigned by EBPP to the customer.
    * @member {String} id_customer
    */
  exports.prototype['id_customer'] = undefined;
    /**
    * The unique identifier assigned by EBPP to the funding account
    * @member {String} id_funding_account
    */
  exports.prototype['id_funding_account'] = undefined;
    /**
    * The unique identifier assigned by EBPP to the customer account
    * @member {String} id_customer_account
    */
  exports.prototype['id_customer_account'] = undefined;
    /**
    * The confirmation number or reference provided to the customer for the successful payment.
    * @member {String} confirmation_number
    */
  exports.prototype['confirmation_number'] = undefined;
    /**
    * The status of the payment. This can take multiple values in the format key=value1&key=value2....
    * @member [String] status
    */
  exports.prototype['status'] = undefined;
    /**
    * The schedule type for the payment setup. This can take multiple values in the format key=value1&key=value2....
    * @member [String] payment_schedule_type
    */
  exports.prototype['payment_schedule_type'] = undefined;
    /**
    * The fulfillment method for the payment.
    * @member [String] payment_method
    */
  exports.prototype['payment_method'] = undefined;
    /**
    * The date from which payments, matching the criteria specified, need to be retrieved.
    * @member {String} from_date
    */
  exports.prototype['from_date'] = undefined;
    /**
    * The date upto which payments, matching the criteria specified, need to be retrieved.
    * @member {String} to_date
    */
  exports.prototype['to_date'] = undefined;
    /**
    * The maximum number of objects returned in the query.
    * @member {String} page_size
    */
  exports.prototype['page_size'] = undefined;

  /**
  * @param  {String} client_key - The client_key of Payments. 
  * @return {module:wrappers/Payments} The instance of <code>Payments</code>.
  */
  exports.prototype.forClient = function (client_key) {
        var _this = this;
	    Base.prototype.forClient.call(_this,client_key);
        return _this;
  };
  /**
  * @param  {String} channel - The channel of Payments. 
  * @return {module:wrappers/Payments} The instance of <code>Payments</code>.
  */
  exports.prototype.videChannel = function (channel) {
        var _this = this;
	    Base.prototype.videChannel.call(_this,channel);
        return _this;
  };
  /**
  * @param  {String} id_funding_account - The id_funding_account of Payments. 
  * @param  {String} id_customer_account - The id_customer_account of Payments. 
  * @param  {String} confirmation_number - The confirmation_number of Payments. 
  * @param  [String] payment_schedule_type - The payment_schedule_type of Payments. 
  * @param  {String} from_date - The from_date of Payments. 
  * @param  {String} to_date - The to_date of Payments. 
  * @param  [String] status - The status of Payments. 
  * @param  {String} page_size - The page_size of Payments. 
  * @param  {String} query_id - The query_id of Payments. 
  * @param  {String} from_index - The from_index of Payments. 
  * @param  {String} to_index - The to_index of Payments. 
  * @return {module:wrappers/Payments} The instance of <code>Payments</code>.
  */
  exports.prototype.findBy = function (filterParameters) {
        var _this = this;
        if(filterParameters){
        
        _this['id_funding_account'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'id_funding_account', false);
        
        _this['id_customer_account'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'id_customer_account', false);
        
        _this['confirmation_number'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'confirmation_number', false);
        _this['payment_schedule_type'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'payment_schedule_type', true);
        
        
        _this['from_date'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'from_date', false);
        
        _this['to_date'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'to_date', false);
        _this['status'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'status', true);
        
        
        _this['page_size'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'page_size', false);
        
        _this['query_id'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'query_id', false);
        
        _this['from_index'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'from_index', false);
        
        _this['to_index'] = CommonUtil.getValuesFromMultiMap(filterParameters, 'to_index', false);
        }
        return _this;
  };
  /**
  * @param  {String} id_customer - The id_customer of Payments. 
  * @return {module:wrappers/Payments} The instance of <code>Payments</code>.
  */
  exports.prototype.forCustomer = function (id_customer) {
        var _this = this;

        _this['id_customer'] = id_customer;


        return _this;
  };

  exports.prototype.retrievedBy = function (requestor, requestor_type) {
        var _this = this;
        _this.requestedBy(requestor, requestor_type);
        return _this;
  };

  exports.prototype.get = function (invocation_context, callback, live_mode, api_end_point) {
        var _this = this;
        var internalCallback = function (errorMessage, parsedData, httpResponse, exception) {
            try {
                var response = ResponseWrapper.wrapResponse(exports, exception, errorMessage, parsedData, httpResponse);
                if (callback) {
                    callback(response['exception'], response['data'])
                }
            } catch (e) {
                exception = OrbipayApiError.getDefaultException(e);
                if (callback) {
                    callback(exception)
                }
            }
        };
        try {
			_this.withContext(invocation_context, live_mode, api_end_point);
			var handler = new RetrievePaymentsHandler();
			if (callback && CommonUtil.isFunction(callback)) {
			    return handler.process(_this, internalCallback);
			} else {
			    return handler.process(_this);
			}
		}
		catch (e){
		    var error = OrbipayApiError.getDefaultException(e);
		    if (callback) {
		        callback(error)
		    }
        }
  };

  return exports;

}));