package com.r3944realms.leashedplayer.datagen;

import com.r3944realms.leashedplayer.LeashedPlayer;
import com.r3944realms.leashedplayer.datagen.provider.*;
import com.r3944realms.leashedplayer.utils.Enum.LanguageEnum;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.data.event.GatherDataEvent;

import java.util.concurrent.CompletableFuture;

@EventBusSubscriber(modid = LeashedPlayer.MOD_ID, bus = EventBusSubscriber.Bus.MOD)
public class ModDataGeneratorHandler {
    @SubscribeEvent
    public static void genData(GatherDataEvent.Client event) {
        CompletableFuture<HolderLookup.Provider> holderFolder = event.getLookupProvider();
        /*Language Provider ENGLISH CHINESE(SIM/TRA)*/
        addLanguage(event, LanguageEnum.English);
        addLanguage(event, LanguageEnum.SimpleChinese);
        addLanguage(event, LanguageEnum.TraditionalChinese);
        addLanguage(event, LanguageEnum.LiteraryChinese);
        ModDataPackBuiltInEntriesProvider(event, holderFolder);
        RecipeGenerator(event, holderFolder);
        ModTagsProvider(event, holderFolder);
        ModPaintVariantTagsProvider(event, holderFolder);
        ModSoundProvider(event);
        ModModelDataGenerate(event);
        ModAdvancementProvider(event, holderFolder);
    }
    private static void addLanguage(GatherDataEvent event, LanguageEnum language){
        event.getGenerator().addProvider(
                true,
                (DataProvider.Factory<ModLanguageProvider>) pOutput -> new ModLanguageProvider(pOutput, LeashedPlayer.MOD_ID, language)
        );
    }

    private static void RecipeGenerator(GatherDataEvent event, CompletableFuture<HolderLookup.Provider> future) {
        PackOutput packOutput = event.getGenerator().getPackOutput();
        event.getGenerator().addProvider(
                true,
                new ModRecipeProvider.Runner(packOutput, future)
        );
    }
    private static void ModTagsProvider(GatherDataEvent event, CompletableFuture<HolderLookup.Provider> completableFuture) {
        ModBlockTagProvider modBlockTagProvider = event.getGenerator().addProvider(
                true,
                (DataProvider.Factory<ModBlockTagProvider>) pOutput -> {
                    return new ModBlockTagProvider(pOutput, completableFuture, LeashedPlayer.MOD_ID);
                }

        );
        event.getGenerator().addProvider(
                true,
                (DataProvider.Factory<ModItemTagProvider>) pOutput ->
                        new ModItemTagProvider(pOutput, completableFuture, modBlockTagProvider.contentsGetter())
        );
    }
    private static void ModSoundProvider(GatherDataEvent event) {
        event.getGenerator().addProvider(
                true,
                (DataProvider.Factory<ModSoundDefinitionsProvider>) pOutput ->
                        new ModSoundDefinitionsProvider(pOutput,LeashedPlayer.MOD_ID)
        );
    }
    private static void ModDataPackBuiltInEntriesProvider(GatherDataEvent event, CompletableFuture<HolderLookup.Provider> future) {
        event.getGenerator().addProvider(
                true,
                (DataProvider.Factory<ModDataPackBuiltInEntriesProvider>) pOutput -> new ModDataPackBuiltInEntriesProvider(pOutput, future)
        );
    }
    private static void ModAdvancementProvider(GatherDataEvent event, CompletableFuture<HolderLookup.Provider> pLookUpProvider) {
        event.getGenerator().addProvider(
                true,
                (DataProvider.Factory<ModAdvancementProvider>) pOutput -> new ModAdvancementProvider(pOutput, pLookUpProvider));
    }
    private static void ModPaintVariantTagsProvider(GatherDataEvent event, CompletableFuture<HolderLookup.Provider> completableFuture) {
        event.getGenerator().addProvider(
                true,
                (DataProvider.Factory<ModPaintingVariantTagsProvider>) pOutput -> {
                    return new ModPaintingVariantTagsProvider(pOutput, completableFuture, LeashedPlayer.MOD_ID);
                }
        );
    }
    private static void ModModelDataGenerate(GatherDataEvent event) {
        event.getGenerator().addProvider(
          true,
                (DataProvider.Factory<ModModelDataProvider>) pOutput -> new ModModelDataProvider(pOutput, LeashedPlayer.MOD_ID)
        );
    }

}
