package com.r3944realms.leashedplayer.content.items;

import com.r3944realms.leashedplayer.LeashedPlayer;
import com.r3944realms.leashedplayer.content.entities.ModEntityRegister;
import com.r3944realms.leashedplayer.content.items.type.*;
import com.r3944realms.leashedplayer.datagen.provider.attributes.ModJukeboxSongs;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.JukeboxSong;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.alchemy.PotionContents;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.neoforge.common.DeferredSpawnEggItem;
import net.neoforged.neoforge.registries.DeferredRegister;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

public class ModItemRegister {
    public static final DeferredRegister<Item> ITEMS =
            DeferredRegister.create(BuiltInRegistries.ITEM, LeashedPlayer.MOD_ID);

    public static final List<Supplier<Item>> ITEM_SUPPLIER = new ArrayList<>();

    public static final Supplier<Item> LEASH_ROPE_ARROW = ModItemRegister.register("leash_rope_arrow",
            () -> new LeashRopeArrowItem(new Item.Properties().stacksTo(16))
    );
    public static final Supplier<Item> SPECTRAL_LEASH_ROPE_ARROW = ModItemRegister.register("spectral_leash_rope_arrow",
            () -> new SpectralLeashRopeArrowItem(new Item.Properties().stacksTo(16)));

    public static final Supplier<Item> TIPPED_LEASH_ROPE_ARROW = ModItemRegister.register("tipped_leash_rope_arrow",
            () -> new TippedLeashRopeArrow(new Item.Properties().stacksTo(16).component(DataComponents.POTION_CONTENTS, PotionContents.EMPTY)));

    public static final Supplier<Item>  NESTLE_ROPE_ARROW = ModItemRegister.register("nestle_rope_arrow",
            () -> new NestleRopeArrowItem(new Item.Properties().stacksTo(16)));

    public static final Supplier<Item> AMETHYST_SHEARS = ModItemRegister.register("amethyst_shears",
            () -> new LeadBreakerItem(ModToolTier.AMETHYST, new Item.Properties().component(DataComponents.TOOL, LeadBreakerItem.createToolProperties())
                    .stacksTo(1)));

    public static final Supplier<Item> KID_SPAWN_EGG = ModItemRegister.register("kid_spawn_egg",
            () -> new DeferredSpawnEggItem(ModEntityRegister.KID, 0x3F4F1F, 0x3D0D4D, new Item.Properties()));

    public static final Supplier<Item> FABRIC = ModItemRegister.register("fabric",
            () -> new TestProcessBarItem(new Item.Properties().stacksTo(1))
    );

    public static final Supplier<Item> NEOFORGE =  ModItemRegister.register("neoforge",
            () -> new CanEquipOnHead(DistProperties(ModJukeboxSongs.FOX_MUSIC)));

    public static Item.Properties DistProperties(ResourceKey<JukeboxSong> song) {
        return new Item.Properties().stacksTo(1).rarity(Rarity.RARE).jukeboxPlayable(song);
    }
    public static Supplier<Item> register(String name, Supplier<Item> supplier) {
        return register(name, supplier, true);
    }

    public static Supplier<Item> register(String name, Supplier<Item> supplier, boolean shouldJoinSupplierLists) {
        Supplier<Item> supplierItem = ITEMS.register(name, supplier);
        if(shouldJoinSupplierLists) ITEM_SUPPLIER.add(supplierItem);
        return supplierItem;
    }

    public static void register(IEventBus eventBus) {
        ITEMS.register(eventBus);
    }
}
