package org.knowm.xchange.quadrigacx.dto.account;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.knowm.xchange.currency.Currency;

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;

public final class QuadrigaCxBalance {

  private Map<String, BigDecimal> currencyReserved = new HashMap<>();
  private Map<String, BigDecimal> currencyAvailable = new HashMap<>();
  private Map<String, BigDecimal> currencyBalance = new HashMap<>();
  private List<Currency> currencies = new ArrayList<>();

  private final BigDecimal fee;

  private final String error;

  public QuadrigaCxBalance(@JsonProperty("fee") BigDecimal fee, @JsonProperty("error") String error, @JsonProperty("fees") Object fees) {

    this.fee = fee;
    this.error = error;
  }

  @JsonAnySetter
  public void setCurrencyAmount(String currencyBalance, BigDecimal amount) {

    String[] parts = currencyBalance.split("_");
    if (parts.length > 1) {
      switch (parts[1]) {
        case "reserved":
          this.currencyReserved.put(parts[0], amount);
          break;
        case "available":
          this.currencyAvailable.put(parts[0], amount);
          break;
        case "balance":
          this.currencyBalance.put(parts[0], amount);
          break;
      }
      Currency currency = new Currency(parts[0]);
      if (!currencies.contains(currency))
        currencies.add(currency);
    }
  }

  public BigDecimal getCurrencyBalance(Currency currency) {
    return this.currencyBalance.get(currency.getCurrencyCode().toLowerCase());
  }

  public BigDecimal getCurrencyReserved(Currency currency) {
    return this.currencyReserved.get(currency.getCurrencyCode().toLowerCase());
  }

  public BigDecimal getCurrencyAvailable(Currency currency) {
    return this.currencyAvailable.get(currency.getCurrencyCode().toLowerCase());
  }

  public List<Currency> getCurrencyList() {
    return this.currencies;
  }

  public BigDecimal getFee() {

    return fee;
  }

  public String getError() {

    return error;
  }

  @Override
  public String toString() {
    return "QuadrigaCxBalance{" + "currencyReserved=" + currencyReserved + ", currencyAvailable=" + currencyAvailable + ", currencyBalance="
        + currencyBalance + ", fee=" + fee + ", error='" + error + '\'' + '}';
  }
}

@@ -55,282 +55,281 @@
 ort 
-java.math.BigDecimal;%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Aimport org.knowm.xchange.currency.Currency;%0A%0Aimport com.fasterxml.jackson.annotation.JsonAnySetter;%0Aimport com.fasterxml.jackson.annotation.JsonProperty
+com.fasterxml.jackson.annotation.JsonAnySetter;%0Aimport com.fasterxml.jackson.annotation.JsonProperty;%0Aimport org.knowm.xchange.currency.Currency;%0A%0Aimport java.math.BigDecimal;%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0Ap
@@ -373,38 +373,40 @@
 %0A%0A  private Map%3C
-String
+Currency
 , BigDecimal%3E cu
@@ -445,38 +445,40 @@
 ;%0A  private Map%3C
-String
+Currency
 , BigDecimal%3E cu
@@ -526,22 +526,24 @@
 ate Map%3C
-String
+Currency
 , BigDec
@@ -1037,16 +1037,87 @@
 t(%22_%22);%0A
+    Currency currency = Currency.getInstance(parts%5B0%5D.toUpperCase());%0A%0A
     if (
@@ -1219,32 +1219,32 @@
 eserved.put(
-parts%5B0%5D
+currency
 , amount);%0A 
@@ -1318,32 +1318,32 @@
 ailable.put(
-parts%5B0%5D
+currency
 , amount);%0A 
@@ -1417,24 +1417,24 @@
 nce.put(
-parts%5B0%5D
+currency
 , amount
@@ -1465,57 +1465,8 @@
   %7D%0A
-      Currency currency = new Currency(parts%5B0%5D);
 %0A   
@@ -1657,40 +1657,8 @@
 ency
-.getCurrencyCode().toLowerCase()
 );%0A 
@@ -1771,40 +1771,8 @@
 ency
-.getCurrencyCode().toLowerCase()
 );%0A 
@@ -1887,40 +1887,8 @@
 ency
-.getCurrencyCode().toLowerCase()
 );%0A 

fix QuadrigaCxBalance so that it correctly translates currencies back into their constant values