// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package data;

import java.util.*;
import org.json.JSONObject;

/** A class representing a billing account object. */
public class Account {
  private String accountID;
  private String vendorID;
  private String entity;
  private String currency;
  private String direction;
  private String legacyAccountID;
  private int nextGenAccountID;
  private String matchingMode;
  private String aggregationMode;

  public Account(String accountID, String vendorID, String entity, 
    String currency, String direction, String legacyAccountID, 
    int nextGenAccountID, String matchingMode, String aggregationMode) {

    this.accountID = accountID;
    this.vendorID = vendorID;
    this.entity = entity;
    this.currency = currency;
    this.direction = direction;
    this.legacyAccountID = legacyAccountID;
    this.nextGenAccountID = nextGenAccountID;
    this.matchingMode = matchingMode;
    this.aggregationMode = aggregationMode;
  }

  public String getAccountID() {
    return accountID;
  }

  public void setAccountID(String accountID) {
    this.accountID = accountID;
  }

  public String getVendorID() {
    return vendorID;  
  }

  public void setVendorID(String vendorID) {
    this.vendorID = vendorID;
  }

  public String getEntity() {
    return entity;
  }

  public void setEntity(String entity) {
    this.entity = entity;
  }

  public String getCurrency() {
    return currency;
  }

  public void setCurrency(String currency) {
    this.currency = currency;
  }

  public String getDirection() {
    return direction;
  }

  public void setDirection(String direction) {
    this.direction = direction;
  }

  public String getLegacyAccountID() {
    return legacyAccountID;
  }

  public void setLegacyAccountID(String legacyAccountID) {
    this.legacyAccountID = legacyAccountID;
  }

  public int getNextGenAccountID() {
    return nextGenAccountID;
  }

  public void setNextGenAccountID(int nextGenAccountID) {
    this.nextGenAccountID = nextGenAccountID;
  }

  public String getMatchingMode() {
    return matchingMode;
  }

  public void setMatchingMode(String matchingMode) {
    this.matchingMode = matchingMode;
  }

  public String getAggregationMode() {
    return aggregationMode;
  }

  public void setAggregationMode(String aggregationMode) {
    this.aggregationMode = aggregationMode;
  }

  // Create and return a JSON object that contains Account fields.
  public LinkedHashMap toJson() {
    // Use LinkedHashMap to preserve order.
    LinkedHashMap accountMap = new LinkedHashMap();
    LinkedHashMap settlementAttributesMap = new LinkedHashMap();

    // Create a JSON objects to contain Account fields.
    JSONObject settlementConfig = new JSONObject();

    // Populate settlementConfig JSON object. LEARN HOW TO PUT QUOTES AROUND A VARIABLE
    settlementConfig.put("Matching_Mode", getMatchingMode());

    // Populate settlementAttributes JSON object.
    settlementAttributesMap.put("Currency_Code", getCurrency());
    settlementAttributesMap.put("Direction", getDirection());
    settlementAttributesMap.put("Entity", getEntity());

    // Populate JSON account object.
    accountMap.put("Legacy_Account_ID", getLegacyAccountID());
    accountMap.put("Next_Gen_Customer_ID", getNextGenAccountID());
    accountMap.put("Settlement_Attributes", settlementAttributesMap);
    accountMap.put("Settlement_Config", settlementConfig);
    accountMap.put("Account_ID", getAccountID());
    accountMap.put("Aggregation_Mode", getAggregationMode());

    return accountMap;
  }
}
@@ -2923,55 +2923,44 @@
 %0A  /
-/ Create and return a JSON object that contains
+** Return a String representation of
  Acc
@@ -2971,16 +2971,19 @@
  fields.
+ */
 %0A  publi
@@ -2988,472 +2988,264 @@
 lic 
-LinkedHashMap toJson() %7B%0A    // Use LinkedHashMap to preserve order.%0A    LinkedHashMap accountMap = new LinkedHashMap();%0A    LinkedHashMap settlementAttributesMap = new LinkedHashMap();%0A%0A    // Create a JSON objects to contain Account fields.%0A    JSONObject settlementConfig = new JSONObject(
+String toString() %7B%0A    StringBuilder accountBuilder = new StringBuilder();%0A    accountBuilder.append(%22%7BLegacy_Account_ID:%22 + getLegacyAccountID()
 );%0A
-%0A
     
-// Populate settlementConfig JSON object. LEARN HOW TO PUT QUOTES AROUND A VARIABLE%0A    settlementConfig.put(%22Matching_Mode%22, getMatchingMode
+accountBuilder.append(%22,Next_Gen_Customer_ID:%22 +  getNextGenAccountID
 ());%0A
-%0A
     
-// Populate s
+accountBuilder.append(%22,S
 ettl
@@ -3241,32 +3241,33 @@
 end(%22,Settlement
+_
 Attributes JSON 
@@ -3264,53 +3264,39 @@
 utes
- JSON object.%0A    settlementAttributesMap.put
+:%7B%22);%0A    accountBuilder.append
 (%22Cu
@@ -3306,18 +3306,20 @@
 ncy_Code
-%22,
+:%22 +
  getCurr
@@ -3335,37 +3335,32 @@
     
-settlementAttributesMap.put
+accountBuilder.append
 (%22
+,
 Dire
@@ -3364,18 +3364,20 @@
 irection
-%22,
+:%22 +
  getDire
@@ -3394,45 +3394,42 @@
     
-settlementAttributesMap.put
+accountBuilder.append
 (%22
+,
 Entity
-%22,
+:%22 +
  get
@@ -3440,328 +3440,167 @@
 ty()
+ + %22%7D%22
 );%0A
-%0A
     
-// Populate JSON account object.%0A    accountMap.put(%22Legacy_Account_ID%22, getLegacyAccountID());%0A    accountMap.put(%22Next_Gen_Customer_ID%22, getNextGenAccountID());%0A    accountMap.put(%22Settlement_Attributes%22, settlementAttributesMap);%0A    accountMap.put(%22Settlement_Config%22, settlementConfig);%0A    accountMap.put
+accountBuilder.append(%22,Settlement_Config:%7B%22);%0A    accountBuilder.append(%22Matching_Mode:%22 + getMatchingMode() + %22%7D%22);%0A    accountBuilder.append
 (%22
+,
 Acco
@@ -3605,18 +3605,20 @@
 count_ID
-%22,
+:%22 +
  getAcco
@@ -3642,17 +3642,25 @@
 ount
-Map.put
+Builder.append
 (%22
+,
 Aggr
@@ -3671,18 +3671,20 @@
 ion_Mode
-%22,
+:%22 +
  getAggr
@@ -3696,16 +3696,23 @@
 onMode()
+ + %22%7D%7D%22
 );%0A%0A    
@@ -3729,11 +3729,26 @@
 ount
-Map
+Builder.toString()
 ;%0A  

switch from toJson to toString to return Account content