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

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

      /**
      * Constructs a <code>CustomerAccount</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/CustomerAccount} obj Optional instance to populate.
      * @return {module:wrappers/CustomerAccount} The populated <code>CustomerAccount</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('customer_account_reference')) {
                obj['customer_account_reference'] = data['customer_account_reference'];
            }
            if (data.hasOwnProperty('account_number')) {
                obj['account_number'] = data['account_number'];
            }
            if (data.hasOwnProperty('current_balance')) {
                obj['current_balance'] = data['current_balance'];
            }
            if (data.hasOwnProperty('current_statement_balance')) {
                obj['current_statement_balance'] = data['current_statement_balance'];
            }
            if (data.hasOwnProperty('minimum_payment_due')) {
                obj['minimum_payment_due'] = data['minimum_payment_due'];
            }
            if (data.hasOwnProperty('past_amount_due')) {
                obj['past_amount_due'] = data['past_amount_due'];
            }
            if (data.hasOwnProperty('payment_due_date')) {
                obj['payment_due_date'] = data['payment_due_date'];
            }
            if (data.hasOwnProperty('statement_date')) {
                obj['statement_date'] = data['statement_date'];
            }
            if (data.hasOwnProperty('id')) {
                obj['id'] = data['id'];
            }
            if (data.hasOwnProperty('url')) {
                obj['url'] = data['url'];
            }
            if (data.hasOwnProperty('status')) {
                obj['status'] = data['status'];
            }
            if (data.hasOwnProperty('custom_fields')) {
                obj['custom_fields'] = data['custom_fields'];
            }
            if (data.hasOwnProperty('comments')) {
                obj['comments'] = data['comments'];
            }
            if (data.hasOwnProperty('audit_info')) {
                var AuditInfo = require('./AuditInfo');
                obj['audit_info'] = AuditInfo.constructFromObject(data['audit_info']);
            }
            if (data.hasOwnProperty('ID_CUSTOMER_ACCOUNT')) {
                obj['ID_CUSTOMER_ACCOUNT'] = data['ID_CUSTOMER_ACCOUNT'];
            }
            if (data.hasOwnProperty('ID_CUSTOMER')) {
                obj['ID_CUSTOMER'] = data['ID_CUSTOMER'];
            }
        }
        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 unique identifier in the client system for the customer account.
    * @member {String} customer_account_reference
    */
  exports.prototype['customer_account_reference'] = undefined;
    /**
    * The number or reference that a customer uses to identify the customer's account.
    * @member {String} account_number
    */
  exports.prototype['account_number'] = undefined;
    /**
    * The current balance on the customer's account with the biller.
    * @member {String} current_balance
    */
  exports.prototype['current_balance'] = undefined;
    /**
    * The balance on the customer’s account with the biller as reported on the last statement.
    * @member {String} current_statement_balance
    */
  exports.prototype['current_statement_balance'] = undefined;
    /**
    * The minimum payment amount, as specified by the biller, that needs to be made against the customer’s account.
    * @member {String} minimum_payment_due
    */
  exports.prototype['minimum_payment_due'] = undefined;
    /**
    * The amount that is due from the past bills/statements on the customer’s account with the biller.
    * @member {String} past_amount_due
    */
  exports.prototype['past_amount_due'] = undefined;
    /**
    * The date by which the customer needs to clear the dues against the customer's account with the biller. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
    * @member {String} payment_due_date
    */
  exports.prototype['payment_due_date'] = undefined;
    /**
    * The date on which the biller generates the statement for the customer's account. It must be in ISO8601 full-date format, namely, YYYY-MM-DD.
    * @member {String} statement_date
    */
  exports.prototype['statement_date'] = undefined;
    /**
    * Id is a unique identifier assigned to the customer account in EBPP.
    * @member {String} id
    */
  exports.prototype['id'] = undefined;
    /**
    * This URL fetches the Account details.
    * @member {String} url
    */
  exports.prototype['url'] = undefined;
    /**
    * The status of the customer's account in EBPP. 
    * @member {String} status
    */
  exports.prototype['status'] = undefined;
    /**
    * The additional information or meta-information that EBPP can accept, maintain and transmit back to the client. The custom fields need to be configured with EBPP before they can be accepted. EBPP 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 EBPP, would be accepted in the requests.
    * @member {{String: String}} custom_fields
    */
  exports.prototype['custom_fields'] = 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 (EBPP) 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;
    /**
    * @member {AuditInfo} audit_info
    */
  exports.prototype['audit_info'] = undefined;
    /**
    * The unique identifier assigned by EBPP to the Customer Account.
    * @member {String} ID_CUSTOMER_ACCOUNT
    */
  exports.prototype['ID_CUSTOMER_ACCOUNT'] = undefined;
    /**
    * The unique identifier assigned by EBPP to the customer.
    * @member {String} ID_CUSTOMER
    */
  exports.prototype['ID_CUSTOMER'] = undefined;

  /**
  * @param  {String} client_key - The client_key of CustomerAccount. 
  * @return {module:wrappers/CustomerAccount} The instance of <code>CustomerAccount</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 CustomerAccount. 
  * @return {module:wrappers/CustomerAccount} The instance of <code>CustomerAccount</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 CustomerAccount. 
  * @param  {String} nickname - The nickname of CustomerAccount. 
  * @param  {String} account_number - The account_number of CustomerAccount. 
  * @param  {String} minimum_payment_due - The minimum_payment_due of CustomerAccount. 
  * @param  {String} past_amount_due - The past_amount_due of CustomerAccount. 
  * @param  {String} payment_due_date - The payment_due_date of CustomerAccount. 
  * @param  {String} statement_date - The statement_date of CustomerAccount. 
  * @return {module:wrappers/CustomerAccount} The instance of <code>CustomerAccount</code>.
  */
  exports.prototype.withDetails = function (account_holder_name, nickname, account_number, minimum_payment_due, past_amount_due, payment_due_date, statement_date) {
        var _this = this;

        _this['account_holder_name'] = account_holder_name;

        _this['nickname'] = nickname;

        _this['account_number'] = account_number;

        _this['minimum_payment_due'] = minimum_payment_due;

        _this['past_amount_due'] = past_amount_due;

        _this['payment_due_date'] = payment_due_date;

        _this['statement_date'] = statement_date;


        return _this;
  };
  /**
  * @param  {String} current_balance - The current_balance of CustomerAccount. 
  * @param  {String} current_statement_balance - The current_statement_balance of CustomerAccount. 
  * @return {module:wrappers/CustomerAccount} The instance of <code>CustomerAccount</code>.
  */
  exports.prototype.withBalances = function (current_balance, current_statement_balance) {
        var _this = this;

        _this['current_balance'] = current_balance;

        _this['current_statement_balance'] = current_statement_balance;


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

        _this['customer_account_reference'] = customer_account_reference;


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

        _this['status'] = status;


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

        _this['address'] = address;


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

        _this['custom_fields'] = custom_fields;


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

        _this['comments'] = comments;


        return _this;
  };
  /**
  * @param  {String} ID_CUSTOMER - The ID_CUSTOMER of CustomerAccount. 
  * @return {module:wrappers/CustomerAccount} The instance of <code>CustomerAccount</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.renewedBy = 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 GetCustomerAccountHandler();
			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.renew = 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 RenewCustomerAccountHandler();
			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;

}));