package com.tiedup.remake.dispenser;

import com.tiedup.remake.core.TiedUpMod;
import com.tiedup.remake.items.ModItems;
import net.minecraft.world.level.block.DispenserBlock;

/**
 * Registration class for all TiedUp dispenser behaviors.
 *
 * Allows dispensers to:
 * - Equip bondage items (via data-driven V2 system) on entities
 * - Shoot rope arrows
 *
 * Note: V1 per-variant dispenser registrations have been removed.
 * Data-driven bondage items use a single universal dispenser behavior
 * registered via DataDrivenBondageItem system.
 *
 * Based on original behaviors package from 1.12.2
 */
public class DispenserBehaviors {

    /**
     * Register all dispenser behaviors.
     * Should be called from TiedUpMod.commonSetup() using enqueueWork().
     */
    public static void register() {
        TiedUpMod.LOGGER.info(
            "[DispenserBehaviors] Registering dispenser behaviors..."
        );

        registerClothesBehaviors();
        registerRopeArrowBehavior();
        registerBondageItemBehavior();

        TiedUpMod.LOGGER.info(
            "[DispenserBehaviors] Dispenser behaviors registered!"
        );
    }

    private static void registerClothesBehaviors() {
        DispenserBlock.registerBehavior(
            ModItems.CLOTHES.get(),
            new ClothesDispenseBehavior()
        );
    }

    private static void registerBondageItemBehavior() {
        // Single registration for the V2 data-driven item singleton.
        // GenericBondageDispenseBehavior inspects the stack's definition to determine behavior.
        if (com.tiedup.remake.v2.bondage.V2BondageItems.DATA_DRIVEN_ITEM != null) {
            DispenserBlock.registerBehavior(
                com.tiedup.remake.v2.bondage.V2BondageItems.DATA_DRIVEN_ITEM.get(),
                GenericBondageDispenseBehavior.forAnyDataDriven()
            );
        }
    }

    private static void registerRopeArrowBehavior() {
        DispenserBlock.registerBehavior(
            ModItems.ROPE_ARROW.get(),
            new RopeArrowDispenseBehavior()
        );
    }
}
