package ru.dbotthepony.mc.otm.compat.jei

import mezz.jei.api.recipe.RecipeType
import mezz.jei.api.recipe.transfer.IRecipeTransferInfo
import net.minecraft.world.inventory.MenuType
import net.minecraft.world.inventory.Slot
import net.minecraft.world.item.crafting.Recipe
import ru.dbotthepony.mc.otm.menu.MatteryMenu
import java.util.*

inline fun <reified M : MatteryMenu, R : Recipe<*>> simpleTransferInfo(type: RecipeType<R>, crossinline slots: (M) -> List<Slot>): IRecipeTransferInfo<M, R> {
	return object : IRecipeTransferInfo<M, R> {
		override fun getContainerClass(): Class<out M> {
			return M::class.java
		}

		override fun getMenuType(): Optional<MenuType<M>> {
			return Optional.empty()
		}

		override fun getRecipeType(): RecipeType<R> {
			return type
		}

		override fun canHandle(container: M, recipe: R): Boolean {
			return true
		}

		override fun getRecipeSlots(container: M, recipe: R): List<Slot> {
			return slots.invoke(container)
		}

		override fun getInventorySlots(container: M, recipe: R): List<Slot> {
			return container.playerInventorySlots
		}
	}
}

inline fun <reified M : MatteryMenu, R : Recipe<*>> simpleTransferInfo0(type: RecipeType<R>, crossinline slot: (M) -> Slot): IRecipeTransferInfo<M, R> {
	return simpleTransferInfo(type) { listOf(slot.invoke(it)) }
}
