(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/AddFundingAccountHandler')
, require('../handlers/DeleteFundingAccountHandler')
, require('../handlers/GetFundingAccountHandler')
, require('../handlers/ReplaceFundingAccountHandler')
, require('../handlers/UpdateFundingAccountHandler'), require('../OrbipayApiError'));
  }
}(this, function(ApiClient, InvocationContext, CommonUtil, ResponseWrapper, Base, AddFundingAccountHandler, DeleteFundingAccountHandler, GetFundingAccountHandler, ReplaceFundingAccountHandler, UpdateFundingAccountHandler, OrbipayApiError) {
  'use strict';

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

      /**
      * Constructs a <code>FundingAccount</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/FundingAccount} obj Optional instance to populate.
      * @return {module:wrappers/FundingAccount} The populated <code>FundingAccount</code> instance.
      */
  exports.constructFromObject = function (data, obj) {
        if (data) {
            obj = obj || new exports();
            if (data.hasOwnProperty('account_holder_name')) {
                obj['account_holder_name'] = data['account_holder_name'];
            }
            if (data.hasOwnProperty('nickname')) {
                obj['nickname'] = data['nickname'];
            }
            if (data.hasOwnProperty('address')) {
                var Address = require('./Address');
                obj['address'] = Address.constructFromObject(data['address']);
            }
            if (data.hasOwnProperty('account_number')) {
                obj['account_number'] = data['account_number'];
            }
            if (data.hasOwnProperty('aba_routing_number')) {
                obj['aba_routing_number'] = data['aba_routing_number'];
            }
            if (data.hasOwnProperty('issuer_name')) {
                obj['issuer_name'] = data['issuer_name'];
            }
            if (data.hasOwnProperty('currency_code3d')) {
                obj['currency_code3d'] = data['currency_code3d'];
            }
            if (data.hasOwnProperty('expiry_date')) {
                obj['expiry_date'] = data['expiry_date'];
            }
            if (data.hasOwnProperty('account_holder_type')) {
                obj['account_holder_type'] = data['account_holder_type'];
            }
            if (data.hasOwnProperty('custom_fields')) {
                obj['custom_fields'] = data['custom_fields'];
            }
            if (data.hasOwnProperty('account_subtype')) {
                obj['account_subtype'] = data['account_subtype'];
            }
            if (data.hasOwnProperty('id')) {
                obj['id'] = data['id'];
            }
            if (data.hasOwnProperty('url')) {
                obj['url'] = data['url'];
            }
            if (data.hasOwnProperty('ach_eligible_flag')) {
                obj['ach_eligible_flag'] = data['ach_eligible_flag'];
            }
            if (data.hasOwnProperty('atm_eligible_flag')) {
                obj['atm_eligible_flag'] = data['atm_eligible_flag'];
            }
            if (data.hasOwnProperty('card_cvv_number')) {
                obj['card_cvv_number'] = data['card_cvv_number'];
            }
            if (data.hasOwnProperty('account_type')) {
                obj['account_type'] = data['account_type'];
            }
            if (data.hasOwnProperty('status')) {
                obj['status'] = data['status'];
            }
            if (data.hasOwnProperty('device_manufacturer_id')) {
                obj['device_manufacturer_id'] = data['device_manufacturer_id'];
            }
            if (data.hasOwnProperty('display_text')) {
                obj['display_text'] = data['display_text'];
            }
            if (data.hasOwnProperty('comments')) {
                obj['comments'] = data['comments'];
            }
            if (data.hasOwnProperty('deleted')) {
                obj['deleted'] = data['deleted'];
            }
            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_FUNDING_ACCOUNT')) {
                obj['ID_FUNDING_ACCOUNT'] = data['ID_FUNDING_ACCOUNT'];
            }
        }
        return obj;
  };


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

    /**
    * The name as specified on the account.
    * @member {String} account_holder_name
    */
  exports.prototype['account_holder_name'] = undefined;
    /**
    * The nickname by which a customer might want to identify the account.
    * @member {String} nickname
    */
  exports.prototype['nickname'] = undefined;
    /**
    * @member {Address} address
    */
  exports.prototype['address'] = undefined;
    /**
    * The number or reference that a customer uses to identify the funding account. In case of Apple Pay, this is the device-specific account number of the card.
    * @member {String} account_number
    */
  exports.prototype['account_number'] = undefined;
    /**
    * The ABA/Routing number for the bank account.
    * @member {String} aba_routing_number
    */
  exports.prototype['aba_routing_number'] = undefined;
    /**
    * The name of the authority that has issued the account. This is relevant only in the case of bank accounts.
    * @member {String} issuer_name
    */
  exports.prototype['issuer_name'] = 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 expiry date for the card. This is to be in the format MM/YY.
    * @member {String} expiry_date
    */
  exports.prototype['expiry_date'] = undefined;
    /**
    * The type of ownership for the funding account. This is applicable only in the case of bank accounts and it is defaults to personal. 
    * @member {String} account_holder_type
    */
  exports.prototype['account_holder_type'] = 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 sub type of the funding account. This is derived by Orbipay in the case of card funding accounts. It needs to be passed when adding or editing a DDA/Bank/ApplePay account. For e.g., a savings account, a checking account.
    * @member {String} account_subtype
    */
  exports.prototype['account_subtype'] = undefined;
    /**
    * Id is a unique identifier assigned to the funding account in Orbipay. A new Id is generated for the funding account when the account number is updated.
    * @member {String} id
    */
  exports.prototype['id'] = undefined;
    /**
    * This URL fetches the funding account details.
    * @member {String} url
    */
  exports.prototype['url'] = undefined;
    /**
    * Indicates if the funding account can be debited vide ACH, in case the funding account is a Demand Deposit Account (DDA).
    * @member {String} ach_eligible_flag
    */
  exports.prototype['ach_eligible_flag'] = undefined;
    /**
    * Indicates if the funding account can be debited vide the ATM Rail network, in case the funding account is a Debit Card.
    * @member {String} atm_eligible_flag
    */
  exports.prototype['atm_eligible_flag'] = undefined;
    /**
    * This is never returned by Orbipay. This needs to be passed to Orbipay when adding or editing a card funding account.
    * @member {String} card_cvv_number
    */
  exports.prototype['card_cvv_number'] = undefined;
    /**
    * The type of the funding account.
    * @member {String} account_type
    */
  exports.prototype['account_type'] = undefined;
    /**
    * The status of the funding account in Orbipay.
    * @member {String} status
    */
  exports.prototype['status'] = undefined;
    /**
    * This is applicable only for Apple Pay transactions. Hex-encoded device manufacturer identifier.
    * @member {String} device_manufacturer_id
    */
  exports.prototype['device_manufacturer_id'] = undefined;
    /**
    * UI representation of the account.
    * @member {String} display_text
    */
  exports.prototype['display_text'] = 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 funding account which says whether the funding account is deleted or not
    * @member {String} deleted
    */
  exports.prototype['deleted'] = 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 Funding Account.
    * @member {String} ID_FUNDING_ACCOUNT
    */
  exports.prototype['ID_FUNDING_ACCOUNT'] = undefined;

  /**
  * @param  {String} client_key - The client_key of FundingAccount. 
  * @return {module:wrappers/FundingAccount} The instance of <code>FundingAccount</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 FundingAccount. 
  * @return {module:wrappers/FundingAccount} The instance of <code>FundingAccount</code>.
  */
  exports.prototype.videChannel = function (channel) {
        var _this = this;
	    Base.prototype.videChannel.call(_this,channel);
        return _this;
  };
  /**
  * @param  {String} account_holder_name - The account_holder_name of FundingAccount. 
  * @param  {String} nickname - The nickname of FundingAccount. 
  * @param  {String} account_number - The account_number of FundingAccount. 
  * @param  {String} account_subtype - The account_subtype of FundingAccount. 
  * @param  {String} aba_routing_number - The aba_routing_number of FundingAccount. 
  * @param  {String} card_cvv_number - The card_cvv_number of FundingAccount. 
  * @param  {String} expiry_date - The expiry_date of FundingAccount. 
  * @param  {String} account_holder_type - The account_holder_type of FundingAccount. 
  * @return {module:wrappers/FundingAccount} The instance of <code>FundingAccount</code>.
  */
  exports.prototype.withDetails = function (account_holder_name, nickname, account_number, account_subtype, aba_routing_number, card_cvv_number, expiry_date, account_holder_type) {
        var _this = this;

        _this['account_holder_name'] = account_holder_name;

        _this['nickname'] = nickname;

        _this['account_number'] = account_number;

        _this['account_subtype'] = account_subtype;

        _this['aba_routing_number'] = aba_routing_number;

        _this['card_cvv_number'] = card_cvv_number;

        _this['expiry_date'] = expiry_date;

        _this['account_holder_type'] = account_holder_type;


        return _this;
  };
  /**
  * @param  {String} account_number - The account_number of FundingAccount. 
  * @param  {String} issuer_name - The issuer_name of FundingAccount. 
  * @return {module:wrappers/FundingAccount} The instance of <code>FundingAccount</code>.
  */
  exports.prototype.withRecordedDetails = function (account_number, issuer_name) {
        var _this = this;

        _this['account_number'] = account_number;

        _this['issuer_name'] = issuer_name;


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

        _this['status'] = status;


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

        _this['address'] = address;


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

        _this['custom_fields'] = custom_fields;


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

        _this['comments'] = comments;


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

        _this['ID_CUSTOMER'] = id_customer;


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

        _this['device_manufacturer_id'] = device_manufacturer_id;


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

        _this['display_text'] = display_text;


        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.replacedBy = 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 AddFundingAccountHandler();
			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 DeleteFundingAccountHandler();
			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 GetFundingAccountHandler();
			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.replace = 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 ReplaceFundingAccountHandler();
			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 UpdateFundingAccountHandler();
			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;

}));