package net.woodyfolsom.cs6601.p2;

import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

@XStreamAlias("recipeml")
public class RecipeBook {

	@XStreamImplicit(itemFieldName="recipe")
	private List<Recipe> recipes;
	
	public Recipe getRecipe(int index) {
		return recipes.get(index);
	}
	
	//TODO build an index of recipes by name?
	public Recipe getRecipe(String recipeName) {
		for (Recipe recipe : recipes) {
			if (recipeName.equalsIgnoreCase(recipe.getHead().getTitle())) {
				return recipe;
			}
		}
		return null;
	}
	
	public int getSize() {
		return recipes.size();
	}
}
