package com.tiedup.remake.items;

import com.tiedup.remake.core.TiedUpMod;
import com.tiedup.remake.entities.ModEntities;
import com.tiedup.remake.items.base.*;
import com.tiedup.remake.items.clothes.GenericClothes;
import java.util.EnumMap;
import java.util.Map;
import net.minecraft.world.item.Item;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

/**
 * Mod Items Registration
 * Handles registration of all TiedUp items using DeferredRegister.
 *
 * V1 bondage items (binds, gags, blindfolds, earplugs, mittens, collars, hood, medical gag)
 * have been removed. All bondage items are now data-driven via DataDrivenItemRegistry.
 * Only non-bondage items and knives remain here.
 */
public class ModItems {

    // DeferredRegister for items
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(
        ForgeRegistries.ITEMS,
        TiedUpMod.MOD_ID
    );

    // ========== KNIVES (still V1 — not bondage items) ==========

    /**
     * All knife items (3 variants via KnifeVariant enum)
     */
    public static final Map<KnifeVariant, RegistryObject<Item>> KNIVES =
        registerAllKnives();

    /**
     * Clothes item - uses dynamic textures from URLs.
     * Users can create presets via anvil naming.
     */
    public static final RegistryObject<Item> CLOTHES = ITEMS.register(
        "clothes",
        GenericClothes::new
    );

    // ========== TOOLS ==========

    public static final RegistryObject<Item> WHIP = ITEMS.register(
        "whip",
        ItemWhip::new
    );

    public static final RegistryObject<Item> CHLOROFORM_BOTTLE = ITEMS.register(
        "chloroform_bottle",
        ItemChloroformBottle::new
    );

    public static final RegistryObject<Item> RAG = ITEMS.register(
        "rag",
        ItemRag::new
    );

    public static final RegistryObject<Item> PADLOCK = ITEMS.register(
        "padlock",
        ItemPadlock::new
    );

    public static final RegistryObject<Item> MASTER_KEY = ITEMS.register(
        "master_key",
        ItemMasterKey::new
    );

    public static final RegistryObject<Item> ROPE_ARROW = ITEMS.register(
        "rope_arrow",
        ItemRopeArrow::new
    );

    public static final RegistryObject<Item> PADDLE = ITEMS.register(
        "paddle",
        ItemPaddle::new
    );

    public static final RegistryObject<Item> SHOCKER_CONTROLLER =
        ITEMS.register("shocker_controller", ItemShockerController::new);

    public static final RegistryObject<Item> GPS_LOCATOR = ITEMS.register(
        "gps_locator",
        ItemGpsLocator::new
    );

    public static final RegistryObject<Item> COLLAR_KEY = ITEMS.register(
        "collar_key",
        ItemKey::new
    );

    public static final RegistryObject<Item> LOCKPICK = ITEMS.register(
        "lockpick",
        ItemLockpick::new
    );

    // Taser - Kidnapper's defensive weapon (Fight Back system)
    public static final RegistryObject<Item> TASER = ITEMS.register(
        "taser",
        ItemTaser::new
    );

    // TiedUp! Guide Book - Opens Patchouli documentation
    public static final RegistryObject<Item> TIEDUP_GUIDE = ITEMS.register(
        "tiedup_guide",
        ItemTiedUpGuide::new
    );

    // Command Wand - Gives commands to collared NPCs (Personality System)
    public static final RegistryObject<Item> COMMAND_WAND = ITEMS.register(
        "command_wand",
        ItemCommandWand::new
    );

    // Debug Wand - Testing tool for Personality System (OP item)
    public static final RegistryObject<Item> DEBUG_WAND = ITEMS.register(
        "debug_wand",
        ItemDebugWand::new
    );

    // ========== CELL SYSTEM ITEMS ==========

    public static final RegistryObject<Item> ADMIN_WAND = ITEMS.register(
        "admin_wand",
        ItemAdminWand::new
    );

    public static final RegistryObject<Item> CELL_KEY = ITEMS.register(
        "cell_key",
        ItemCellKey::new
    );

    // ========== SLAVE TRADER SYSTEM ==========

    public static final RegistryObject<Item> TOKEN = ITEMS.register(
        "token",
        ItemToken::new
    );

    // ========== SPAWN EGGS ==========

    /**
     * Damsel Spawn Egg
     * Colors: Light Pink (0xFFB6C1) / Hot Pink (0xFF69B4)
     */
    public static final RegistryObject<Item> DAMSEL_SPAWN_EGG = ITEMS.register(
        "damsel_spawn_egg",
        () ->
            new ForgeSpawnEggItem(
                ModEntities.DAMSEL,
                0xFFB6C1, // Light pink (primary)
                0xFF69B4, // Hot pink (secondary)
                new Item.Properties()
            )
    );

    // ========== FACTORY METHODS ==========

    private static Map<KnifeVariant, RegistryObject<Item>> registerAllKnives() {
        Map<KnifeVariant, RegistryObject<Item>> map = new EnumMap<>(
            KnifeVariant.class
        );
        for (KnifeVariant variant : KnifeVariant.values()) {
            map.put(
                variant,
                ITEMS.register(variant.getRegistryName(), () ->
                    new GenericKnife(variant)
                )
            );
        }
        return map;
    }

    // ========== HELPER ACCESSORS ==========

    /**
     * Get a knife item by variant.
     * @param variant The knife variant
     * @return The knife item
     */
    public static Item getKnife(KnifeVariant variant) {
        return KNIVES.get(variant).get();
    }
}
