
/**
 * Note: These recipe schemas are made to help with output unification script. See `server_scripts/squash_duplicates.js`
 * for detail
 * 
 * The reason is that `recipeEvent.replaceOutput(...)` can only be applied to with-schema recipes, as recipe schema is
 * responsible for marking the input/output part of a recipe
 */

StartupEvents.recipeSchemaRegistry((event) => {
    const $FluidComponents = Java.loadClass("dev.latvian.mods.kubejs.recipe.component.FluidComponents");
    const $ItemComponents = Java.loadClass("dev.latvian.mods.kubejs.recipe.component.ItemComponents");
    const $NumberComponent = Java.loadClass("dev.latvian.mods.kubejs.recipe.component.NumberComponent");
    const $RecipeComponent = Java.loadClass("dev.latvian.mods.kubejs.recipe.component.RecipeComponent");
    const $TagKeyComponent = Java.loadClass("dev.latvian.mods.kubejs.recipe.component.TagKeyComponent");
    const $RecipeSchema = Java.loadClass("dev.latvian.mods.kubejs.recipe.schema.RecipeSchema");
    const $RecipeKey = Java.loadClass("dev.latvian.mods.kubejs.recipe.RecipeKey");

    /**
     * @template T
     * @param {string} name 
     * @param {Internal.RecipeComponent<T>} component 
     */
    function recipeKey(name, component) {
        return new $RecipeKey(component, name)
    }

    const singleFluid = $FluidComponents.INPUT
        .or($RecipeComponent.builder(
            recipeKey("tag", $TagKeyComponent.FLUID),
            recipeKey("amount", $NumberComponent.INT)
        ).inputRole())

    event.register("embers:stamping", new $RecipeSchema(
        recipeKey("stamp", $ItemComponents.INPUT),
        recipeKey("output", $ItemComponents.OUTPUT),
        recipeKey("input", $ItemComponents.INPUT).defaultOptional(),
        recipeKey("fluid", singleFluid.asArrayOrSelf()).defaultOptional(),
    ))

    event.register("createdieselgenerators:hammering", new $RecipeSchema(
        recipeKey("ingredients", $ItemComponents.INPUT_ARRAY),
        recipeKey("results", $ItemComponents.OUTPUT_ARRAY)
    ))
})