(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/CreateRecurringPaymentSetupHandler')
, require('../handlers/DeletePaymentSetupHandler')
, require('../handlers/GetPaymentSetupHandler')
, require('../handlers/UpdatePaymentSetupHandler'), require('../OrbipayApiError'));
  }
}(this, function(ApiClient, InvocationContext, CommonUtil, ResponseWrapper, Base, CreateRecurringPaymentSetupHandler, DeletePaymentSetupHandler, GetPaymentSetupHandler, UpdatePaymentSetupHandler, OrbipayApiError) {
  'use strict';

    /**
    * The PaymentSetup wrapper module.
    * @module wrappers/PaymentSetup
    */
  var exports = function(id_payment_setup) {
  	var _this = this;
        Base.call(_this);
  		_this['ID_PAYMENT_SETUP'] = id_payment_setup;
        _this.id = id_payment_setup;
  };

      /**
      * Constructs a <code>PaymentSetup</code> from a plain JavaScript object, optionally creating a new instance.
      * Copies all relevant properties from <code>data</code> to <code>obj</code> if supplied or a new instance if not.
      * @param {Object} data The plain JavaScript object bearing properties of interest.
      * @param {module:wrappers/PaymentSetup} obj Optional instance to populate.
      * @return {module:wrappers/PaymentSetup} The populated <code>PaymentSetup</code> instance.
      */
  exports.constructFromObject = function (data, obj) {
        if (data) {
            obj = obj || new exports();
            if (data.hasOwnProperty('id')) {
                obj['id'] = data['id'];
            }
            if (data.hasOwnProperty('url')) {
                obj['url'] = data['url'];
            }
            if (data.hasOwnProperty('fee')) {
                var Fee = require('./Fee');
                obj['fee'] = Fee.constructFromObject(data['fee']);
            }
            if (data.hasOwnProperty('status')) {
                obj['status'] = data['status'];
            }
            if (data.hasOwnProperty('payment_method')) {
                obj['payment_method'] = data['payment_method'];
            }
            if (data.hasOwnProperty('payment_setup_schedule_type')) {
                obj['payment_setup_schedule_type'] = data['payment_setup_schedule_type'];
            }
            if (data.hasOwnProperty('confirmation_number')) {
                obj['confirmation_number'] = data['confirmation_number'];
            }
            if (data.hasOwnProperty('custom_fields')) {
                obj['custom_fields'] = data['custom_fields'];
            }
            if (data.hasOwnProperty('currency_code3d')) {
                obj['currency_code3d'] = data['currency_code3d'];
            }
            if (data.hasOwnProperty('amount')) {
                obj['amount'] = data['amount'];
            }
            if (data.hasOwnProperty('card_cvv_number')) {
                obj['card_cvv_number'] = data['card_cvv_number'];
            }
            if (data.hasOwnProperty('next_payment_date')) {
                obj['next_payment_date'] = data['next_payment_date'];
            }
            if (data.hasOwnProperty('payment_setup_reference')) {
                obj['payment_setup_reference'] = data['payment_setup_reference'];
            }
            if (data.hasOwnProperty('payment_schedule')) {
                var PaymentSchedule = require('./PaymentSchedule');
                obj['payment_schedule'] = PaymentSchedule.constructFromObject(data['payment_schedule']);
            }
            if (data.hasOwnProperty('payment_setup_entry_date')) {
                obj['payment_setup_entry_date'] = data['payment_setup_entry_date'];
            }
            if (data.hasOwnProperty('comments')) {
                obj['comments'] = data['comments'];
            }
            if (data.hasOwnProperty('deleted')) {
                obj['deleted'] = data['deleted'];
            }
            if (data.hasOwnProperty('customer')) {
                var Customer = require('./Customer');
                obj['customer'] = Customer.constructFromObject(data['customer']);
            }
            if (data.hasOwnProperty('funding_account')) {
                var FundingAccount = require('./FundingAccount');
                obj['funding_account'] = FundingAccount.constructFromObject(data['funding_account']);
            }
            if (data.hasOwnProperty('customer_account')) {
                var CustomerAccount = require('./CustomerAccount');
                obj['customer_account'] = CustomerAccount.constructFromObject(data['customer_account']);
            }
            if (data.hasOwnProperty('payment_network_response')) {
                var PaymentNetworkResponse = require('./PaymentNetworkResponse');
                obj['payment_network_response'] = PaymentNetworkResponse.constructFromObject(data['payment_network_response']);
            }
            if (data.hasOwnProperty('audit_info')) {
                var AuditInfo = require('./AuditInfo');
                obj['audit_info'] = AuditInfo.constructFromObject(data['audit_info']);
            }
            if (data.hasOwnProperty('ID_CUSTOMER')) {
                obj['ID_CUSTOMER'] = data['ID_CUSTOMER'];
            }
            if (data.hasOwnProperty('ID_PAYMENT_SETUP')) {
                obj['ID_PAYMENT_SETUP'] = data['ID_PAYMENT_SETUP'];
            }
        }
        return obj;
  };


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

    /**
    * The unique identifier assigned by Orbipay to the payment setup.
    * @member {String} id
    */
  exports.prototype['id'] = undefined;
    /**
    * This URL fetches the details of payment setup.
    * @member {String} url
    */
  exports.prototype['url'] = undefined;
    /**
    * @member {Fee} fee
    */
  exports.prototype['fee'] = undefined;
    /**
    * The status of the payment.
    * @member {String} status
    */
  exports.prototype['status'] = undefined;
    /**
    * The fulfillment method for the payment.
    * @member {String} payment_method
    */
  exports.prototype['payment_method'] = undefined;
    /**
    * The schedule type for the payment setup.
    * @member {String} payment_setup_schedule_type
    */
  exports.prototype['payment_setup_schedule_type'] = undefined;
    /**
    * The confirmation number or reference provided to the customer for the payment setup.
    * @member {String} confirmation_number
    */
  exports.prototype['confirmation_number'] = undefined;
    /**
    * The additional information or meta-information that Orbipay can accept, maintain and transmit back to the client. The custom fields need to be configured with Orbipay before they can be accepted. Orbipay would reject custom fields that are not pre-configured. Please contact <a href = \"mailto: support@billerpayments.com\">support@billerpayments.com</a> for more information on configuring and using custom fields. Only the custom fields enabled for the client, in Orbipay, would be accepted in the requests.
    * @member {{String: String}} custom_fields
    */
  exports.prototype['custom_fields'] = undefined;
    /**
    * The three-letter currency code in the ISO4217 format, in uppercase, for the card account. It must be a currency supported by Orbipay. This defaults to USD.
    * @member {String} currency_code3d
    */
  exports.prototype['currency_code3d'] = undefined;
    /**
    * The amount being paid. In case the payment_amount_type is 'discounted_amount', 'penalty_amount' or 'other', the amount needs to be specified. In other cases, this is derived from the payment_amount_type.
    * @member {String} amount
    */
  exports.prototype['amount'] = undefined;
    /**
    * This is never returned by Orbipay. This needs to be passed to Orbipay when making or editing a payment setup with a card funding account.
    * @member {String} card_cvv_number
    */
  exports.prototype['card_cvv_number'] = undefined;
    /**
    * The date on which the payment is scheduled to be made. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
    * @member {String} next_payment_date
    */
  exports.prototype['next_payment_date'] = undefined;
    /**
    * The unique identifier in the client system for the payment setup.
    * @member {String} payment_setup_reference
    */
  exports.prototype['payment_setup_reference'] = undefined;
    /**
    * @member {PaymentSchedule} payment_schedule
    */
  exports.prototype['payment_schedule'] = undefined;
    /**
    * The date on which the payment setup is captured in Orbipay. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
    * @member {String} payment_setup_entry_date
    */
  exports.prototype['payment_setup_entry_date'] = undefined;
    /**
    * Comments that can be used to recollect the operation performed on the resource object. API clients need to ensure that no sensitive information is passed in the memo. Alacriti (Orbipay) is not responsible for the security of any sensitive information that may be passed as part of the memo.
    * @member {String} comments
    */
  exports.prototype['comments'] = undefined;
    /**
    * The status of payment which says whether the payment is deleted or not
    * @member {String} deleted
    */
  exports.prototype['deleted'] = undefined;
    /**
    * @member {Customer} customer
    */
  exports.prototype['customer'] = undefined;
    /**
    * @member {FundingAccount} funding_account
    */
  exports.prototype['funding_account'] = undefined;
    /**
    * @member {CustomerAccount} customer_account
    */
  exports.prototype['customer_account'] = undefined;
    /**
    * @member {PaymentNetworkResponse} payment_network_response
    */
  exports.prototype['payment_network_response'] = undefined;
    /**
    * @member {AuditInfo} audit_info
    */
  exports.prototype['audit_info'] = 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 payment setup.
    * @member {String} ID_PAYMENT_SETUP
    */
  exports.prototype['ID_PAYMENT_SETUP'] = undefined;

  /**
  * @param  {String} client_key - The client_key of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</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 PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.videChannel = function (channel) {
        var _this = this;
	    Base.prototype.videChannel.call(_this,channel);
        return _this;
  };
  /**
  * @param  {String} amount - The amount of PaymentSetup. 
  * @param  {String} card_cvv_number - The card_cvv_number of PaymentSetup. 
  * @param  {String} payment_setup_schedule_type - The payment_setup_schedule_type of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.withDetails = function (amount, card_cvv_number, payment_setup_schedule_type) {
        var _this = this;

        _this['amount'] = amount;

        _this['card_cvv_number'] = card_cvv_number;

        _this['payment_setup_schedule_type'] = payment_setup_schedule_type;


        return _this;
  };
  /**
  * @param  {FundingAccount} funding_account - The funding_account of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.fromAccount = function (funding_account) {
        var _this = this;

        _this['funding_account'] = funding_account;


        return _this;
  };
  /**
  * @param  {CustomerAccount} customer_account - The customer_account of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.toAccount = function (customer_account) {
        var _this = this;

        _this['customer_account'] = customer_account;


        return _this;
  };
  /**
  * @param  {String} payment_setup_reference - The payment_setup_reference of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.withReference = function (payment_setup_reference) {
        var _this = this;

        _this['payment_setup_reference'] = payment_setup_reference;


        return _this;
  };
  /**
  * @param  {PaymentSchedule} payment_schedule - The payment_schedule of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.withPaymentSchedule = function (payment_schedule) {
        var _this = this;

        _this['payment_schedule'] = payment_schedule;


        return _this;
  };
  /**
  * @param  {String} status - The status of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.withStatus = function (status) {
        var _this = this;

        _this['status'] = status;


        return _this;
  };
  /**
  * @param  {{String: String}} custom_fields - The custom_fields of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.withCustomFields = function (custom_fields) {
        var _this = this;

        _this['custom_fields'] = custom_fields;


        return _this;
  };
  /**
  * @param  {String} comments - The comments of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.withMemo = function (comments) {
        var _this = this;

        _this['comments'] = comments;


        return _this;
  };
  /**
  * @param  {Fee} fee - The fee of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.withFee = function (fee) {
        var _this = this;

        _this['fee'] = fee;


        return _this;
  };
  /**
  * @param  {String} ID_CUSTOMER - The ID_CUSTOMER of PaymentSetup. 
  * @return {module:wrappers/PaymentSetup} The instance of <code>PaymentSetup</code>.
  */
  exports.prototype.forCustomer = function (id_customer) {
        var _this = this;

        _this['ID_CUSTOMER'] = id_customer;
        var Customer = require('./Customer');
        _this['customer'] = new Customer(id_customer);


        return _this;
  };

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

  exports.prototype.create = 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 CreateRecurringPaymentSetupHandler();
			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)
		    }
        }
  };
  exports.prototype.delete = 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 DeletePaymentSetupHandler();
			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)
		    }
        }
  };
  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 GetPaymentSetupHandler();
			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)
		    }
        }
  };
  exports.prototype.update = 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 UpdatePaymentSetupHandler();
			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;

}));