package com.tiedup.remake.entities.ai.master;

/**
 * Enum defining the types of tasks a Master can assign to their pet.
 */
public enum PetTask {
    /**
     * Heel - Pet must stay within 3 blocks of Master.
     * Punishment: Choke if distance > 3 blocks
     */
    HEEL("Heel, pet. Stay close to me. [Stay within 3 blocks]", 1200, 3.0),

    /**
     * Wait Here - Pet cannot move from current position.
     * Punishment: Choke if moves more than 2 blocks
     */
    WAIT_HERE("Stay here. Don't move. [Stay within 2 blocks]", 800, 2.0),

    /**
     * Fetch Item - Pet must give Master a specific item.
     * Punishment: Choke if item not given within time limit
     */
    FETCH_ITEM("Bring me %s. [Right-click on me with the item]", 2400, 0.0),

    /**
     * Kneel - Pet must crouch and not move.
     * Punishment if pet stands up or moves.
     */
    KNEEL("Kneel. [Hold shift, don't move]", 600, 1.5),

    /**
     * Come - Pet must reach Master quickly.
     * Speed test - must be within range before time runs out.
     */
    COME("Come here! Now! [Reach me within 10 seconds]", 200, 2.0),

    /**
     * Present - Pet must stand near Master without moving.
     * Punishment if pet moves away.
     */
    PRESENT(
        "Present yourself. Stand before me. [Stand still near me]",
        400,
        2.0
    ),

    /**
     * Speak - Pet must right-click on Master.
     * Interaction-based task.
     */
    SPEAK("Speak, pet. [Right-click on me]", 300, 0.0),

    /**
     * Drop - Pet must empty both hands.
     * Punishment if hands are not empty.
     */
    DROP("Drop what you're holding. [Empty both hands]", 400, 0.0),

    /**
     * Follow Close - Like HEEL but tighter distance, longer duration.
     * Punishment if pet strays more than 1.5 blocks.
     */
    FOLLOW_CLOSE(
        "Stay right beside me. Don't stray. [Stay within 1.5 blocks]",
        1600,
        1.5
    ),

    /**
     * Demand - Master demands a valuable item from pet's inventory.
     * Scans inventory and picks the most precious item the pet has.
     * Interaction-based completion (same as FETCH_ITEM).
     */
    DEMAND("Give me that %s. Now. [Right-click on me with the item]", 600, 0.0),

    /**
     * Random Bind - Master puts a random bind/accessory on pet temporarily.
     * This is not really a "task" but an event.
     */
    RANDOM_BIND("Hold still...", 0, 0.0),

    /**
     * Dogwalk - Master initiates a walk with the pet.
     * Not a task per se, but a special event.
     */
    DOGWALK("Time for a walk.", 0, 0.0);

    private final String messageTemplate;
    private final int durationTicks;
    private final double maxDistance;

    PetTask(String messageTemplate, int durationTicks, double maxDistance) {
        this.messageTemplate = messageTemplate;
        this.durationTicks = durationTicks;
        this.maxDistance = maxDistance;
    }

    /**
     * Get the message template for this task.
     * May contain %s for item names.
     */
    public String getMessageTemplate() {
        return messageTemplate;
    }

    /**
     * Get the duration of this task in ticks.
     */
    public int getDurationTicks() {
        return durationTicks;
    }

    /**
     * Get the maximum allowed distance for distance-based tasks.
     * For HEEL: max distance from Master.
     * For WAIT_HERE: max distance from starting position.
     */
    public double getMaxDistance() {
        return maxDistance;
    }

    /**
     * Check if this task requires distance monitoring.
     */
    public boolean requiresDistanceCheck() {
        return (
            this == HEEL ||
            this == WAIT_HERE ||
            this == FOLLOW_CLOSE ||
            this == KNEEL ||
            this == PRESENT
        );
    }

    /**
     * Check if this is a real task (vs an event like RANDOM_BIND or DOGWALK).
     */
    public boolean isRealTask() {
        return (
            this == HEEL ||
            this == WAIT_HERE ||
            this == FETCH_ITEM ||
            this == KNEEL ||
            this == COME ||
            this == PRESENT ||
            this == SPEAK ||
            this == DROP ||
            this == FOLLOW_CLOSE ||
            this == DEMAND
        );
    }

    /**
     * Check if this task requires the pet to be crouching.
     */
    public boolean requiresCrouching() {
        return this == KNEEL;
    }

    /**
     * Check if this task requires an interaction to complete.
     */
    public boolean requiresInteraction() {
        return this == SPEAK || this == DEMAND;
    }

    /**
     * Check if this task requires empty hands.
     */
    public boolean requiresEmptyHands() {
        return this == DROP;
    }
}
