package org.innovateuk.ifs.project.grantofferletter.viewmodel;

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

import static java.util.Collections.singletonList;

/*
 * Holder of values for the other costs rows on GOL finance tables, which are handled differently
 */
public class OtherCostsRowModel {

    private final String otherCostName;
    private Map<String, List<BigDecimal>> otherCostValues;

    public OtherCostsRowModel(String otherCostName,
                              Map<String, List<BigDecimal>> otherCostValues) {
        this.otherCostName = otherCostName;
        this.otherCostValues = otherCostValues;
    }

    public String getOtherCostName() {
        return otherCostName;
    }

    public Map<String, List<BigDecimal>> getOtherCostValues() {
        return otherCostValues;
    }

    public void addToCostValues(String orgName, BigDecimal cost) {
        if(otherCostValues.keySet().contains(orgName)) {
            otherCostValues.get(orgName).add(cost);
        } else {
            otherCostValues.put(orgName, singletonList(cost));
        }
    }
}

@@ -86,16 +86,45 @@
 ecimal;%0A
+import java.util.Collection;%0A
 import j
@@ -1133,11 +1133,316 @@
  %7D%0A    %7D
+%0A%0A    public Collection%3CString%3E getOrganisations() %7B%0A        return otherCostValues.keySet();%0A    %7D%0A%0A    public BigDecimal getCostValuesForOrg(String organisation) %7B%0A        return otherCostValues.get(organisation)%0A                .stream()%0A                .reduce(BigDecimal.ZERO, BigDecimal::add);%0A    %7D
 %0A%7D%0A

Add helper methods to other costs rows