package ru.dbotthepony.mc.otm.registry;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import ru.dbotthepony.mc.otm.OverdriveThatMatters;
import ru.dbotthepony.mc.otm.recipe.EnergyContainerRecipe;
import ru.dbotthepony.mc.otm.recipe.ExplosiveHammerPrimingRecipe;
import ru.dbotthepony.mc.otm.recipe.PlatePressRecipe;
import ru.dbotthepony.mc.otm.recipe.UpgradeRecipe;

public class MRecipes {
	public static class MatteryRecipeType<T extends Recipe<?>> implements RecipeType<T> {
		public final ResourceLocation name;

		private MatteryRecipeType(ResourceLocation name) {
			this.name = name;
		}

		@Override
		public String toString() {
			return name.toString();
		}
	}

	public static final MatteryRecipeType<PlatePressRecipe> PLATE_PRESS = new MatteryRecipeType<>(OverdriveThatMatters.loc(MNames.PLATE_PRESS));
	public static final MatteryRecipeType<PlatePressRecipe> ENERGY_CONTAINER = new MatteryRecipeType<>(OverdriveThatMatters.loc("energy_container"));
	public static final MatteryRecipeType<PlatePressRecipe> UPGRADE = new MatteryRecipeType<>(OverdriveThatMatters.loc("upgrade"));
	public static final MatteryRecipeType<PlatePressRecipe> HAMMER_PRIMING = new MatteryRecipeType<>(OverdriveThatMatters.loc("hammer_priming"));

	private static final DeferredRegister<RecipeSerializer<?>> serializerRegistry = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS, OverdriveThatMatters.MOD_ID);
	private static final DeferredRegister<RecipeType<?>> typeRegistry = DeferredRegister.create(ForgeRegistries.RECIPE_TYPES, OverdriveThatMatters.MOD_ID);

	static {
		serializerRegistry.register(MNames.PLATE_PRESS, () -> PlatePressRecipe.Companion);
		serializerRegistry.register(ENERGY_CONTAINER.name.getPath(), () -> EnergyContainerRecipe.Companion);
		serializerRegistry.register(UPGRADE.name.getPath(), () -> UpgradeRecipe.Companion);
		serializerRegistry.register(HAMMER_PRIMING.name.getPath(), () -> ExplosiveHammerPrimingRecipe.Companion);

		typeRegistry.register(MNames.PLATE_PRESS, () -> PLATE_PRESS);
		typeRegistry.register(ENERGY_CONTAINER.name.getPath(), () -> ENERGY_CONTAINER);
		typeRegistry.register(UPGRADE.name.getPath(), () -> UPGRADE);
		typeRegistry.register(HAMMER_PRIMING.name.getPath(), () -> HAMMER_PRIMING);
	}

	public static void register(IEventBus bus) {
		serializerRegistry.register(bus);
		typeRegistry.register(bus);
	}
}
