package top.r3944realms.lib39.base.datagen;

import net.minecraft.data.DataProvider;
import net.minecraftforge.data.event.GatherDataEvent;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.base.datagen.provider.*;
import top.r3944realms.lib39.base.datagen.value.Lib39LangKey;
import top.r3944realms.lib39.datagen.provider.SimpleLanguageProvider;
import top.r3944realms.lib39.datagen.provider.SimpleLootTableProvider;
import top.r3944realms.lib39.datagen.provider.SubProvidersWrapper;
import top.r3944realms.lib39.datagen.value.McLocale;

/**
 * The type Lib 39 base data gen event.
 */
public class Lib39BaseDataGenEvent {
    /**
     * The Logger.
     */
    static Logger logger = LoggerFactory.getLogger(Lib39BaseDataGenEvent.class);

    /**
     * Gather data.
     *
     * @param event the event
     */
    public static void gatherData(GatherDataEvent event) {
        logger.info("GatherDataEvent thread: {}", Thread.currentThread().getName());
        LanguageGenerator(event, McLocale.EN_US);
        LanguageGenerator(event, McLocale.ZH_CN);
        LanguageGenerator(event, McLocale.ZH_TW);
        LanguageGenerator(event, McLocale.LZH);
        BlockModelDataGenerate(event);
        BlockStateDataGenerate(event);
        ItemModelDataGenerate(event);
        LootTableDataGenerate(event);
        SoundDefinitionDataGenerate(event);
        RecipeGenerator(event);
    }
    private static void LanguageGenerator(@NotNull GatherDataEvent event, McLocale language) {
        event.getGenerator().addProvider(
                event.includeClient(),
                (DataProvider.Factory<SimpleLanguageProvider>) pOutput -> new SimpleLanguageProvider(pOutput, Lib39.MOD_ID ,language , Lib39LangKey.INSTANCE)
        );
    }
    private static void ItemModelDataGenerate(@NotNull GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeClient(),
                (DataProvider.Factory<Lib39ItemModelProvider>) pOutput -> new Lib39ItemModelProvider(pOutput, event.getExistingFileHelper())
        );
    }
    private static void BlockModelDataGenerate(@NotNull GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeClient(),
                (DataProvider.Factory<Lib39BlockModelProvider>) pOutput -> new Lib39BlockModelProvider(pOutput, event.getExistingFileHelper())
        );
    }
    private static void BlockStateDataGenerate(@NotNull GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeClient(),
                (DataProvider.Factory<Lib39BlockStatesProvider>) pOutput -> new Lib39BlockStatesProvider(pOutput, event.getExistingFileHelper())
        );
    }
    private static void SoundDefinitionDataGenerate(@NotNull GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeClient(),
                (DataProvider.Factory<Lib39SoundDefinitionsProvider>) pOutput -> new Lib39SoundDefinitionsProvider(pOutput, event.getExistingFileHelper())
        );
    }
    private static void LootTableDataGenerate(@NotNull GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeServer(),
                (DataProvider.Factory<SimpleLootTableProvider>) pOutput -> new SimpleLootTableProvider(pOutput, new SubProvidersWrapper().addBlockEntry(new Lib39BlockLootTable()))
        );
    }
    private static void RecipeGenerator(@NotNull GatherDataEvent event) {
        event.getGenerator().addProvider(
                event.includeServer(),
                (DataProvider.Factory<Lib39RecipeProvider>) Lib39RecipeProvider::new
        );
    }
}
