/*
 *  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.provider;

import net.minecraft.core.HolderLookup;
import net.minecraft.data.PackOutput;
import net.minecraft.data.tags.ItemTagsProvider;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.r3944realms.eroticdungeongame.EroticDungeon;
import top.r3944realms.eroticdungeongame.core.register.EDGItems;
import top.r3944realms.eroticdungeongame.core.register.tag.EDGItemTags;

import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

public class EDGItemTagProvider extends ItemTagsProvider {
    public EDGItemTagProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, CompletableFuture<TagLookup<Block>> blockTags, @Nullable ExistingFileHelper existingFileHelper) {
        super(output, lookupProvider, blockTags, EroticDungeon.MOD_ID, existingFileHelper);
    }

    @Override
    protected void addTags(HolderLookup.@NotNull Provider provider) {
        addTagFromStream(EDGItemTags.SEAT, EDGItems.SEAT_ITEMS.stream());
        addTagFromCollection(EDGItemTags.CUFF_BED, EDGItems.CUFF_BED_ITEMS.values());
        addTagFromCollection(EDGItemTags.RACK, EDGItems.RACK_ITEMS.values());
        addTagFromCollection(EDGItemTags.X_CROSS, EDGItems.X_CROSS_ITEMS.values());
        addTagFromCollection(EDGItemTags.PETRINE_CROSS, EDGItems.PETRINE_CROSS_ITEMS.values());
        addTagFromCollection(EDGItemTags.CRUX, EDGItems.CRUX_ITEMS.values());
        addTagFromCollection(EDGItemTags.SPANISH_DONKEY, EDGItems.SPANISH_DONKEY_ITEMS.values());
        addTagFromCollection(EDGItemTags.PILLORY, EDGItems.PILLORY_ITEMS.values());
        addTagFromCollection(EDGItemTags.WALL_RACK, EDGItems.WALL_RACK_ITEMS.values());
        addTagFromCollection(EDGItemTags.CUFF_POLE, EDGItems.CUFF_POLE_ITEMS.values());
        addTagFromCollection(EDGItemTags.PRONE_BENCH, EDGItems.PRONE_BENCH_ITEMS.values());
        addTagFromCollection(EDGItemTags.HANGING_POST, EDGItems.HANGING_POST_ITEMS.values());
    }
    private void addTagFromStream(TagKey<Item> tag, @NotNull Stream<RegistryObject<Item>> stream) {
        tag(tag).add(stream.map(RegistryObject::get).toArray(Item[]::new));
    }

    private void addTagFromCollection(TagKey<Item> tag, @NotNull Collection<RegistryObject<Item>> collection) {
        tag(tag).add(collection.stream().map(RegistryObject::get).toArray(Item[]::new));
    }
}
