package exnihilocreatio.compatibility.jei.barrel.fluiditemtransform;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import exnihilocreatio.registries.types.FluidBlockTransformer;
import exnihilocreatio.registries.types.FluidItemFluid;
import exnihilocreatio.util.Util;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.ingredients.VanillaTypes;
import mezz.jei.api.recipe.IRecipeWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;

import javax.annotation.Nonnull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class FluidItemTransformRecipe implements IRecipeWrapper {

    @Nonnull
    private final FluidStack inputFluid;
    @Nonnull
    private final ItemStack inputBucket;
    @Nonnull
    private final List<ItemStack> inputStacks;

    @Nonnull
    private final ItemStack outputStack;

    public FluidItemTransformRecipe(FluidBlockTransformer recipe) {
        inputFluid = new FluidStack(FluidRegistry.getFluid(recipe.getFluidName()), 1000);

        inputBucket = Util.getBucketStack(inputFluid.getFluid());

        inputStacks = Arrays.asList(recipe.getInput().getMatchingStacks());
        outputStack = recipe.getOutput().getItemStack();
    }

    public FluidItemTransformRecipe(FluidItemFluid recipe) {
        inputFluid = new FluidStack(FluidRegistry.getFluid(recipe.getInputFluid()), 1000);
        inputBucket = Util.getBucketStack(inputFluid.getFluid());
        inputStacks = Collections.singletonList(recipe.getReactant().getItemStack());

        outputStack = Util.getBucketStack(FluidRegistry.getFluid(recipe.getOutput()));
    }

    @Override
    public void getIngredients(@Nonnull IIngredients ingredients) {
        ingredients.setInputLists(VanillaTypes.ITEM, getInputs());
        ingredients.setInputs(VanillaTypes.FLUID, getFluidInputs());

        ingredients.setOutput(VanillaTypes.ITEM, outputStack);
    }

    public List<List<ItemStack>> getInputs() {
        return ImmutableList.of(Collections.singletonList(inputBucket), inputStacks);
    }

    public ItemStack getOutput() {
        return outputStack;
    }

    public List<FluidStack> getFluidInputs() {
        return ImmutableList.of(inputFluid);
    }

    public boolean isValid() {
        return !inputBucket.isEmpty() && !inputStacks.isEmpty() && !outputStack.isEmpty();
    }

    @Override
    public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {

    }

    @Override
    @Nonnull
    public List<String> getTooltipStrings(int mouseX, int mouseY) {
        return Lists.newArrayList();
    }

    @Override
    public boolean handleClick(@Nonnull Minecraft minecraft, int mouseX, int mouseY, int mouseButton) {
        return false;
    }
}

@@ -607,16 +607,59 @@
 idStack;
+%0Aimport org.jetbrains.annotations.Nullable;
 %0A%0Aimport
@@ -1000,16 +1000,72 @@
 tacks;%0A%0A
+    @Nullable%0A    private final FluidStack outputFluid;%0A
     @Non
@@ -1466,24 +1466,52 @@
 temStack();%0A
+        outputFluid = null;%0A
     %7D%0A%0A    p
@@ -1828,30 +1828,25 @@
 tput
-Stack = Util.getBucket
+Fluid = new Fluid
 Stac
@@ -1889,16 +1889,89 @@
 utput())
+, 1000);%0A        outputStack = Util.getBucketStack(outputFluid.getFluid()
 );%0A    %7D
@@ -2187,24 +2187,24 @@
 Inputs());%0A%0A
-
         ingr
@@ -2254,16 +2254,116 @@
 Stack);%0A
+        if(outputFluid != null)%0A            ingredients.setOutput(VanillaTypes.FLUID, outputFluid);%0A
     %7D%0A%0A 

Make FluidItemTransform JEI plugin show results it the fluid block instead of just the bucket is used to look up recipes.