package com.ic.invoicecapture;

import com.ic.invoicecapture.connection.ApiRequestFacade;
import com.ic.invoicecapture.connection.response.validators.ValidatorBuilder;
import com.ic.invoicecapture.exceptions.IcException;
import com.ic.invoicecapture.model.Debt;
import com.ic.invoicecapture.model.DebtField;
import com.ic.invoicecapture.model.IRoutable;
import java.net.URI;
import java.util.Map;

public class DebtApiFacade extends ApiBase {

  public static final String DEBTS_ENDPOINT = "debts";

  public DebtApiFacade(ApiRequestFacade apiFacade) {
    super(apiFacade);
  }

  public DebtApiFacade(String apiToken, URI baseUrl) {
    super(apiToken, baseUrl);
  }

  public Debt registerNewDebt(Debt debt) throws IcException {
    Map<DebtField, Object> debtMap = debt.toEnumMap();
    return this.registerNewDebt(debtMap);
  }

  public Debt registerNewDebt(Map<DebtField, Object> customerInfo) throws IcException {
    DebtField.assertCorrectlyInitialized(customerInfo);
    String jsonToSend = this.jsonFacade.toJson(customerInfo);
    ValidatorBuilder builder = this.validatorBuilder.clone().addBadClientJsonValidator()
        .addConflictValidator("A debt already exists with the same id");

    return this.returningRequest(Debt.class, builder,
        (validator) -> apiFacade.postRequest(validator, DEBTS_ENDPOINT, jsonToSend));
  }

  public Debt requestDebtInfo(IRoutable routable) throws IcException {
    return requestDebtInfo(routable.getId());
  }
  
  public Debt requestDebtInfo(String id) throws IcException {
    assertCorrectId(id);
    ValidatorBuilder builder = this.validatorBuilder.clone();
    String endpoint = DEBTS_ENDPOINT + "/" + id;
    return this.returningRequest(Debt.class, builder,
        (validator) -> apiFacade.getRequest(validator, endpoint));
  }
}



@@ -880,24 +880,20 @@
 Object%3E 
-customer
+debt
 Info) th
@@ -952,24 +952,20 @@
 ialized(
-customer
+debt
 Info);%0A 
@@ -1014,16 +1014,12 @@
 son(
-customer
+debt
 Info

rename method arg