package com.tiedup.remake.dispenser;

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

/**
 * Registration class for all TiedUp dispenser behaviors.
 *
 * Allows dispensers to:
 * - Equip bondage items (binds, gags, blindfolds, collars, earplugs, clothes) on entities
 * - Shoot rope arrows
 *
 * 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..."
        );

        registerBindBehaviors();
        registerGagBehaviors();
        registerBlindfoldBehaviors();
        registerCollarBehaviors();
        registerEarplugsBehaviors();
        registerClothesBehaviors();
        registerRopeArrowBehavior();

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

    private static void registerBindBehaviors() {
        var behavior = GenericBondageDispenseBehavior.forBind();
        for (BindVariant variant : BindVariant.values()) {
            DispenserBlock.registerBehavior(
                ModItems.getBind(variant),
                behavior
            );
        }
    }

    private static void registerGagBehaviors() {
        var behavior = GenericBondageDispenseBehavior.forGag();
        for (GagVariant variant : GagVariant.values()) {
            DispenserBlock.registerBehavior(ModItems.getGag(variant), behavior);
        }
        DispenserBlock.registerBehavior(ModItems.MEDICAL_GAG.get(), behavior);
        DispenserBlock.registerBehavior(ModItems.HOOD.get(), behavior);
    }

    private static void registerBlindfoldBehaviors() {
        var behavior = GenericBondageDispenseBehavior.forBlindfold();
        for (BlindfoldVariant variant : BlindfoldVariant.values()) {
            DispenserBlock.registerBehavior(
                ModItems.getBlindfold(variant),
                behavior
            );
        }
    }

    private static void registerCollarBehaviors() {
        var behavior = GenericBondageDispenseBehavior.forCollar();
        DispenserBlock.registerBehavior(
            ModItems.CLASSIC_COLLAR.get(),
            behavior
        );
        DispenserBlock.registerBehavior(ModItems.SHOCK_COLLAR.get(), behavior);
        DispenserBlock.registerBehavior(
            ModItems.SHOCK_COLLAR_AUTO.get(),
            behavior
        );
        DispenserBlock.registerBehavior(ModItems.GPS_COLLAR.get(), behavior);
    }

    private static void registerEarplugsBehaviors() {
        var behavior = GenericBondageDispenseBehavior.forEarplugs();
        for (EarplugsVariant variant : EarplugsVariant.values()) {
            DispenserBlock.registerBehavior(
                ModItems.getEarplugs(variant),
                behavior
            );
        }
    }

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

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