package top.azimkin.militaryarmor;

import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.Item;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("unused")
public final class ModItems {
    private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MilitaryArmor.MOD_ID);

    public static final RegistryObject<CommonMilitaryArmorItem> VSU_VEST_1 = ITEMS.register("vsu_vest_1", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.CHESTPLATE,
            new Item.Properties(),
            "vsu_vest_1"
    ));
    public static final RegistryObject<CommonMilitaryArmorItem> VSU_HELMET_1 = ITEMS.register("vsu_helmet_1", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.HELMET,
            new Item.Properties(),
            "vsu_helmet_1"
    ));

    public static final RegistryObject<CommonMilitaryArmorItem> VSU_VEST_2 = ITEMS.register("vsu_vest_2", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.CHESTPLATE,
            new Item.Properties(),
            "vsu_vest_2"
    ));
    public static final RegistryObject<CommonMilitaryArmorItem> VSU_HELMET_2 = ITEMS.register("vsu_helmet_2", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.HELMET,
            new Item.Properties(),
            "vsu_helmet_2"
    ));

    public static final RegistryObject<CommonMilitaryArmorItem> RUS_VEST_1 = ITEMS.register("rus_vest_1", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.CHESTPLATE,
            new Item.Properties(),
            "rus_vest_1"
    ));
    public static final RegistryObject<CommonMilitaryArmorItem> RUS_HELMET_1 = ITEMS.register("rus_helmet_1", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.HELMET,
            new Item.Properties(),
            "rus_helmet_1"
    ));

    public static final RegistryObject<CommonMilitaryArmorItem> RUS_VEST_2 = ITEMS.register("rus_vest_2", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.CHESTPLATE,
            new Item.Properties(),
            "rus_vest_2"
    ));
    public static final RegistryObject<CommonMilitaryArmorItem> RUS_HELMET_2 = ITEMS.register("rus_helmet_2", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.HELMET,
            new Item.Properties(),
            "rus_helmet_2"
    ));

    public static final RegistryObject<CommonMilitaryArmorItem> VEST_1 = ITEMS.register("vest_1", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.CHESTPLATE,
            new Item.Properties(),
            "set_1"
    ));
    public static final RegistryObject<CommonMilitaryArmorItem> HELMET_1 = ITEMS.register("helmet_1", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.HELMET,
            new Item.Properties(),
            "set_1"
    ));

    public static final RegistryObject<CommonMilitaryArmorItem> VEST_2 = ITEMS.register("vest_2", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.CHESTPLATE,
            new Item.Properties(),
            "set_2"
    ));
    public static final RegistryObject<CommonMilitaryArmorItem> HELMET_2 = ITEMS.register("helmet_2", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.HELMET,
            new Item.Properties(),
            "set_2"
    ));

    public static final RegistryObject<CommonMilitaryArmorItem> VEST_3 = ITEMS.register("vest_3", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.CHESTPLATE,
            new Item.Properties(),
            "set_3"
    ));
    public static final RegistryObject<CommonMilitaryArmorItem> HELMET_3 = ITEMS.register("helmet_3", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.HELMET,
            new Item.Properties(),
            "set_3"
    ));

    public static final RegistryObject<CommonMilitaryArmorItem> VEST_4 = ITEMS.register("vest_4", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.CHESTPLATE,
            new Item.Properties(),
            "set_4"
    ));
    public static final RegistryObject<CommonMilitaryArmorItem> HELMET_4 = ITEMS.register("helmet_4", () -> new CommonMilitaryArmorItem(
            ModArmorMaterials.COMMON_MILITARY,
            ArmorItem.Type.HELMET,
            new Item.Properties(),
            "set_4"
    ));

    public static final List<RegistryObject<? extends Item>> ITEM_LIST = new ArrayList<>();

    @SuppressWarnings({"unused", "unchecked"})
    public static void register(IEventBus modBus) {
        ITEMS.register(modBus);

        try {
            for (var f : ModItems.class.getDeclaredFields()) {
                if (Modifier.isStatic(f.getModifiers()) && Modifier.isFinal(f.getModifiers()) && f.getType() == RegistryObject.class) {
                    ITEM_LIST.add(((RegistryObject<? extends Item>) f.get(null)));

                }
            }
        } catch (Throwable throwable) {
            MilitaryArmor.LOGGER.error("Error while trying to register items in a tab", throwable);
        }

    }
}
