/*
 *  Copyright 2025-2026 R3944Realms
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package top.r3944realms.eroticdungeongame.datagen;

import net.minecraft.core.HolderLookup;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.data.event.GatherDataEvent;
import org.jetbrains.annotations.NotNull;
import top.r3944realms.eroticdungeongame.EroticDungeon;
import top.r3944realms.eroticdungeongame.datagen.provider.*;
import top.r3944realms.eroticdungeongame.datagen.value.EDGBlockLootTables;
import top.r3944realms.eroticdungeongame.datagen.value.EDGLangKey;
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;

import java.util.Set;
import java.util.concurrent.CompletableFuture;

public class EDGDataGenEvent {

    public static void gatherData(@NotNull GatherDataEvent event) {
        EroticDungeon.getLogger().info("GatherDataEvent thread: {}", Thread.currentThread().getName());
        DataGenerator gen = event.getGenerator();
        ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
        PackOutput packOutput = gen.getPackOutput();
        CompletableFuture<HolderLookup.Provider> lookupProvider = event.getLookupProvider();
        gen.addProvider(true, new SimpleLanguageProvider(packOutput, EroticDungeon.MOD_ID, McLocale.EN_US, EDGLangKey.INSTANCE));
        gen.addProvider(true, new SimpleLanguageProvider(packOutput, EroticDungeon.MOD_ID, McLocale.ZH_CN, EDGLangKey.INSTANCE));
        gen.addProvider(true, new SimpleLanguageProvider(packOutput, EroticDungeon.MOD_ID, McLocale.ZH_TW, EDGLangKey.INSTANCE));
        gen.addProvider(true, new SimpleLanguageProvider(packOutput, EroticDungeon.MOD_ID, McLocale.LZH, EDGLangKey.INSTANCE));
        gen.addProvider(true, new EDGBlockModelProvider(packOutput, existingFileHelper));
        gen.addProvider(true, new EDGBlockStatesProvider(packOutput, existingFileHelper));
        gen.addProvider(true, new EDGItemModelProvider(packOutput, existingFileHelper));
        EDGBlockTagsProvider blockTagsProvider = new EDGBlockTagsProvider(packOutput, lookupProvider, existingFileHelper);
        gen.addProvider(true, blockTagsProvider);
        gen.addProvider(true, new EDGItemTagProvider(packOutput, lookupProvider, blockTagsProvider.contentsGetter(), existingFileHelper));
        gen.addProvider(true, new EDGSoundDefinitionsProvider(packOutput,existingFileHelper));
        gen.addProvider(true, new SimpleLootTableProvider(packOutput,
                new SubProvidersWrapper()
                        .addBlockEntry(new EDGBlockLootTables())
                        .addEntry(new LootTableProvider.SubProviderEntry(EDGChestLootTable::new, LootContextParamSets.CHEST))
                )
        );
        gen.addProvider(true, new EDGRecipeProvider(packOutput));
        gen.addProvider(true, new EDGPoiTypeTagsProvider(packOutput, lookupProvider, existingFileHelper));
        gen.addProvider(true, new EDGAnimationProvider(gen));
        gen.addProvider(true, new EDGAnimationLayerProvider(gen));
        gen.addProvider(true,
                new DatapackBuiltinEntriesProvider(packOutput, event.getLookupProvider(), EDGRegistries.BUILDER, Set.of(EroticDungeon.MOD_ID))
        );
    }

}
