import java.util.Set;
import java.util.TreeSet;

/**
 * Class that models a list of invoices.  Note: to be generally useful,
 * other methods (e.g., getters and setters) would be added.
 *   @author Dave Reed
 *   @version 1/29/15
 */
public class InvoiceList {
	private Set<Invoice> invoices;
	private int totalUnits;
	private double totalSales;
	
	/** 
	 * Constructs an empty list of invoices.
	 */
	public InvoiceList() {
		this.invoices = new TreeSet<Invoice>();
		this.totalUnits = 0;
		this.totalSales = 0.0;
	}

	/**
	 * Adds an invoice to the list.
	 *   @param inv the list to be added
	 */
	public void add(Invoice inv) {
		this.invoices.add(inv);
		this.totalUnits += inv.getUnits();
		this.totalSales += inv.getUnits() * inv.getPricePerUnit();
	}
	
	/**
	 * Returns a String representation of the list (including totals).
	 *   @return the String representation
	 */
	public String toString() {
		String invStr = "";
		for (Invoice inv : invoices) {
			invStr += inv + "\n";
		}
		return invStr + "Total units = " + totalUnits + "\n" +
				        "Total sales = $" + totalSales;
	}
}
