package net.woodyfolsom.cs6601.p2;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.thoughtworks.xstream.annotations.XStreamAlias;

@XStreamAlias("ing")
public class Ingredient {
	public enum TYPE { ALCOHOL, BEEF, DAIRY, EGGS, FISH, GLUTEN, GRAIN, NUTS, PORK, POULTRY, POTATO, SHELLFISH, SPICE, SUGAR, TOMATO}
	
	private String item;
	
	public String getItem() {
		return item;
	}
	
	public Set<TYPE> getTypes() {
		Set<TYPE> types = new HashSet<TYPE>();
		for (TYPE type : TYPE.values()) {
			if (isType(type)) {
				types.add(type);
			}
		}
		return types;
	}
	
	public boolean isType(TYPE type) {
		switch (type) {
			case BEEF :
				return item.contains("beef");
			case DAIRY :
				return item.contains("margarine");
			case EGGS :
				return item.equals("egg") || item.equals("eggs");
			case GLUTEN :
				return item.contains("flour");
			case PORK :
				return item.contains("pork");
			case POTATO :
				return item.contains("potato");
			case SPICE :
				return item.endsWith("cinnamon") || item.endsWith("nutmeg") || item.endsWith("cloves");
			case SUGAR :
				return item.endsWith("sugar");
			case TOMATO :
				return item.contains("tomato");
			default : //unknown ingredient, e.g. coffee, bananas, honey
				return false;
		}
	}
	
	public Object readResolve() {
		item = item.toLowerCase();
		return this;
	}
}
