package com.leisuretimedock.blasttravelreborn.datagen;

import com.leisuretimedock.blasttravelreborn.BlastTravelReborn;
import com.leisuretimedock.blasttravelreborn.datagen.provider.BTRItemModelProvider;
import com.leisuretimedock.blasttravelreborn.datagen.provider.BTRParticleProvider;
import com.leisuretimedock.blasttravelreborn.datagen.provider.BTRRecipeProvider;
import com.leisuretimedock.blasttravelreborn.datagen.value.BTRLangKeys;
import net.minecraft.data.DataProvider;
import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.lib39.datagen.provider.SimpleLanguageProvider;
import top.r3944realms.lib39.datagen.value.McLocale;

import java.util.Set;

@Mod.EventBusSubscriber(modid = BlastTravelReborn.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class DataGeneratorHandler {
    @SubscribeEvent
    public static void generatorDataEvent(GatherDataEvent event) {
        LanguageGenerate(event, McLocale.EN_US);
        LanguageGenerate(event, McLocale.ZH_CN);
        LanguageGenerate(event, McLocale.ZH_TW);
        ModelDataGenerate(event);
        ParticleGenerate(event);
        RecipeGenerate(event);
        DatapackBuiltinEntriesGenerate(event);
    }

    private static void LanguageGenerate(@NotNull GatherDataEvent event, McLocale language) {
        event.getGenerator().addProvider(
                event.includeClient(),
                (DataProvider.Factory<SimpleLanguageProvider>) pOutput -> new SimpleLanguageProvider(pOutput, BlastTravelReborn.MOD_ID ,language , BTRLangKeys.INSTANCE)
        );
    }
    private static void ModelDataGenerate(GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeClient(),
                (DataProvider.Factory<BTRItemModelProvider>) pOutput -> new BTRItemModelProvider(pOutput, event.getExistingFileHelper())
        );
    }
    private static void RecipeGenerate(GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeServer(),
                (DataProvider.Factory<BTRRecipeProvider>) BTRRecipeProvider::new
        );
    }
    private static void ParticleGenerate(GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeClient(),
                (DataProvider.Factory<BTRParticleProvider>) pOutput -> new BTRParticleProvider(pOutput, event.getExistingFileHelper())
        );
    }
    private static void DatapackBuiltinEntriesGenerate(GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeServer(),
                (DataProvider.Factory<DatapackBuiltinEntriesProvider>) pOutput -> new DatapackBuiltinEntriesProvider(pOutput, event.getLookupProvider(), BTRRegistries.BUILDER, Set.of(BlastTravelReborn.MOD_ID))
        );
    }
}
