package ru.dbotthepony.mc.otm.registry.game

import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.world.item.crafting.Recipe
import net.minecraft.world.item.crafting.RecipeType
import net.neoforged.bus.api.IEventBus
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.core.ResourceLocation
import ru.dbotthepony.mc.otm.recipe.*
import ru.dbotthepony.mc.otm.registry.MDeferredRegister

@Suppress("SameParameterValue")
object MRecipes {
	class Type<T : Recipe<*>>(id: String) : RecipeType<T> {
		val id = ResourceLocation(OverdriveThatMatters.MOD_ID, id)

		override fun toString(): String {
			return "RecipeType[$id]"
		}
	}

	private val types = MDeferredRegister(BuiltInRegistries.RECIPE_TYPE, OverdriveThatMatters.MOD_ID)
	private val serializers = MDeferredRegister(BuiltInRegistries.RECIPE_SERIALIZER, OverdriveThatMatters.MOD_ID)

	fun register(bus: IEventBus) {
		types.register(bus)
		serializers.register(bus)
	}

	private fun <T : Recipe<*>> register(name: String): MDeferredRegister<*>.Entry<Type<T>> {
		return types.register(name) { Type(name) }
	}

	val PLATE_PRESS by register<PlatePressRecipe>("plate_press")
	val PAINTER by register<AbstractPainterRecipe>("painter")
	val MATTER_ENTANGLER by register<IMatterEntanglerRecipe>("matter_entangler")
	val MICROWAVE by register<MicrowaveRecipe>("microwave")

	init {
		serializers.register("plate_press") { PlatePressRecipe.Companion }
		serializers.register("upgrade") { UpgradeRecipe.Companion }
		serializers.register("painter") { PainterRecipe.Companion }
		serializers.register("painter_armor_dye") { PainterArmorDyeRecipe.Companion }
		serializers.register("matter_entangler") { MatterEntanglerRecipe.Companion }
		serializers.register("matter_entangler_energetic") { MatterEntanglerRecipe.EnergySerializer }
		serializers.register("matter_entangler_matter") { MatterEntanglerRecipe.MatterSerializer }
		serializers.register("microwave") { MicrowaveRecipe.Companion }
	}
}
