package com.tiedup.remake.v2.bondage.movement;

import com.tiedup.remake.v2.BodyRegionV2;
import org.jetbrains.annotations.Nullable;

/**
 * Movement styles that change how a bound player physically moves.
 * Each style has a severity (higher = more constraining), default speed multiplier,
 * and default jump-disabled flag.
 *
 * <p>When multiple styled items are worn, the style with the highest severity wins.
 * If two items share the same severity, the item on the region with the lowest
 * {@link com.tiedup.remake.v2.BodyRegionV2#ordinal()} wins.</p>
 *
 * <p>This enum is shared (server + client). It does NOT contain handler references
 * to avoid pulling server-only classes into client code.</p>
 */
public enum MovementStyle {
    /** Swaying side-to-side gait, visual zigzag via animation. Jump allowed. */
    WADDLE(1, 0.6f, false),

    /** Tiny dragging steps, heavy speed reduction. Jump disabled. */
    SHUFFLE(2, 0.4f, true),

    /** Automatic small hops when moving forward. Jump disabled (auto-hop replaces it). */
    HOP(3, 0.35f, true),

    /** On all fours, swim-like hitbox (0.6 high). Jump disabled. */
    CRAWL(4, 0.2f, true);

    private final int severity;
    private final float defaultSpeedMultiplier;
    private final boolean defaultJumpDisabled;

    MovementStyle(
        int severity,
        float defaultSpeedMultiplier,
        boolean defaultJumpDisabled
    ) {
        this.severity = severity;
        this.defaultSpeedMultiplier = defaultSpeedMultiplier;
        this.defaultJumpDisabled = defaultJumpDisabled;
    }

    /** Higher severity = more constraining. Used for resolution tiebreaking. */
    public int getSeverity() {
        return severity;
    }

    /** Default speed multiplier (0.0-1.0) applied via MULTIPLY_BASE AttributeModifier. */
    public float getDefaultSpeedMultiplier() {
        return defaultSpeedMultiplier;
    }

    /** Whether jumping is disabled by default for this style. */
    public boolean isDefaultJumpDisabled() {
        return defaultJumpDisabled;
    }

    /**
     * Safe valueOf that returns null instead of throwing on unknown names.
     *
     * @param name the style name (case-insensitive)
     * @return the style, or null if not recognized
     */
    @Nullable
    public static MovementStyle fromName(String name) {
        if (name == null) return null;
        try {
            return valueOf(name.toUpperCase());
        } catch (IllegalArgumentException e) {
            return null;
        }
    }
}
