package inusualz.mechanics.apiimpl.smasher;

import inusualz.mechanics.api.smasher.ISmasherRecipe;
import inusualz.mechanics.api.smasher.ISmasherRegistry;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

public class SmasherRegistry implements ISmasherRegistry {

    private List<ISmasherRecipe> recipeList = new ArrayList<>();

    @Override
    public void addRecipe(@Nonnull ISmasherRecipe recipe) {
        recipeList.add(recipe);
    }

    @Override
    public boolean removeRecipe(@Nonnull ISmasherRecipe recipe) {
        return removeRecipeByInput(recipe.getInput());
    }

    @Override
    public boolean removeRecipeByInput(@Nonnull ItemStack inputStack) {
        for (int i = 0; i < recipeList.size(); i++) {
            if (recipeList.get(i).getInput().isItemEqual(inputStack)) {
                recipeList.remove(i);
                return true;
            }
        }
        return false;
    }

    @Override
    public ISmasherRecipe getRecipe(@Nonnull ItemStack stack) {
        for (ISmasherRecipe recipe : recipeList) {
            if (recipe.getInput().isItemEqual(stack)) {
                return recipe;
            }
        }
        return null;
    }

    @Override
    public List<ISmasherRecipe> getRecipes() {
        return recipeList;
    }

    @Override
    public ISmasherRecipe createRecipe(@Nonnull ItemStack input, @Nonnull ItemStack output, int duration) {
        return null;
    }

    @Override
    public ISmasherRecipe createRecipe(@Nonnull ItemStack input, @Nonnull ItemStack output, int duration, @Nonnull ItemStack secondaryOutput, int luckyNumber) {
        return null;
    }
}
