package projectzombie.inventory.recipe;

import projectzombie.inventory.Crafting;
import projectzombie.inventory.Inventory;
import projectzombie.util.ItemStack;

public class RecipeBasic implements Recipe
{
	protected ItemStack[] stacks_required;
	protected Crafting[] tools_required;
	protected ItemStack result;
	
	public RecipeBasic(ItemStack[] stacks_required, Crafting[] tools_required, ItemStack result)
	{
		this.stacks_required = stacks_required;
		this.tools_required = tools_required;
		this.result = result;
	}

	@Override
	public ItemStack getResult() {
		return result.copy();
	}

	@Override
	public boolean canCraft(Crafting tool)
	{
		for(Crafting tool_required : tools_required) {
			if(tool == tool_required || tool_required == Crafting.BASIC) {
				return true;
			}
		}
		
		return false;
	}

	@Override
	public boolean hasResourcesToCraft(Inventory inventory)
	{
		for(ItemStack item : stacks_required) {
			if(inventory.getItemCount(item) < item.count) {
				return false;
			}
		}
		
		return true;
	}

	@Override
	public ItemStack craftResult(Inventory inventory)
	{
		for(ItemStack item : stacks_required) {
			inventory.removeItem(item.copy());
		}
		
		return result.copy();
	}

	@Override
	public ItemStack[] getIngredients() {
		return stacks_required;
	}
}
