package au.gov.qld.pub.orders.service;

import java.util.List;

// Warning: do not put anything sensitive in this unless you know your source ID cannot be guessed.
public class PaymentInformation {
    private final long amountOwingInCents;
    private final long amountOwingGstInCents;
    private final String reference;
    private final String description;
	private final List<OrderInformation> orderInformation;

    public PaymentInformation(String reference, String description, long amountOwingInCents, long amountOwingGstInCents, List<OrderInformation> orderInformation) {
        this.reference = reference;
        this.description = description;
        this.amountOwingInCents = amountOwingInCents;
        this.amountOwingGstInCents = amountOwingGstInCents;
		this.orderInformation = orderInformation;
		
		validateAmounts();
    }

    private void validateAmounts() {
    	long totalOrdersOwning = 0;
    	for (OrderInformation order : orderInformation) {
    		totalOrdersOwning += order.getGst();
    		totalOrdersOwning += order.getTotal();    		
    	}
    	
    	if (totalOrdersOwning != amountOwingInCents) {
    		throw new IllegalStateException("Amounts do not add up for " + reference + " Base amount " + amountOwingInCents + " vs " + totalOrdersOwning);
    	}
	}

	public long getAmountOwingInCents() {
        return amountOwingInCents;
    }

    public long getAmountOwingGstInCents() {
        return amountOwingGstInCents;
    }

    public String getReference() {
        return reference;
    }

    public String getDescription() {
        return description;
    }

	public List<OrderInformation> getOrderInformation() {
		return orderInformation;
	}
}

@@ -831,494 +831,12 @@
 n;%0D%0A
-%09%09%0D%0A%09%09validateAmounts();%0D%0A    %7D%0D%0A%0D%0A    private void validateAmounts() %7B%0D%0A    %09long totalOrdersOwning = 0;%0D%0A    %09for (OrderInformation order : orderInformation) %7B%0D%0A    %09%09totalOrdersOwning += order.getGst();%0D%0A    %09%09totalOrdersOwning += order.getTotal();    %09%09%0D%0A    %09%7D%0D%0A    %09%0D%0A    %09if (totalOrdersOwning != amountOwingInCents) %7B%0D%0A    %09%09throw new IllegalStateException(%22Amounts do not add up for %22 + reference + %22 Base amount %22 + amountOwingInCents + %22 vs %22 + totalOrdersOwning);%0D%0A    %09%7D%0D%0A%09
+    
 %7D%0D%0A%0D

move amount validation out to be handled in subprojects