using UnityEngine;

/// <summary>
/// A spottable skeleton patrol event that appears as a red marker within perception range
/// Players can choose to approach and engage or avoid the patrol
/// </summary>
[CreateAssetMenu(fileName = "SpottableSkeletonPatrol", menuName = "RPG/Travel Events/Spottable/Skeleton Patrol")]
public class SpottableSkeletonPatrol : CombatTravelEvent
{
    [Header("Spottable Event Settings")]
    [TextArea(2, 4)]
    public string[] spotDescription = {
        "You spot skeletal figures moving in the distance...",
        "A patrol of undead warriors can be seen ahead...",
        "Your keen eyes detect a group of skeleton warriors patrolling the area..."
    };

    void OnEnable()
    {
        // Configure as spottable event
        triggerType = EventTriggerType.Spottable;

        // Set up the event details
        eventName = "Skeleton Patrol";
        eventDescription = "A patrol of skeleton warriors guards this area. They haven't noticed you yet.";
        eventType = EventType.Combat;
        rarity = EventRarity.Common;

        // Configure combat settings
        minEnemies = 2;
        maxEnemies = 4;
        allowRunningAway = true;
        runAwaySuccessChance = 0.85f; // Higher chance since you can see them coming
        runAwayHealthPenalty = 2; // Lower penalty since you're prepared

        // Set terrain preferences (skeletons prefer ruins, forests, mountains)
        plainsChance = 0.4f;
        forestChance = 0.8f;
        mountainChance = 0.7f;
        roadChance = 0.3f; // Less likely on roads
        townChance = 0.1f; // Very unlikely in settlements
        villageChance = 0.2f;

        // Configure encounter descriptions
        encounterDescriptions = new string[]
        {
            "The skeleton patrol notices your approach and readies their weapons!",
            "The undead warriors turn toward you with hollow, glowing eyes!",
            "The skeleton patrol forms a battle line as you draw near!"
        };

        // Configure escape messages for spotted encounters
        successfulRunAwayMessages = new string[]
        {
            "Having spotted them first, your party easily retreats unnoticed!",
            "Your party backs away quietly before the patrol spots you!",
            "You successfully avoid the skeleton patrol by taking a different route!"
        };

        failedRunAwayMessages = new string[]
        {
            "The skeletons spot your retreat! You take {damage} damage as they give chase!",
            "Your withdrawal is noticed! The patrol pursues, dealing {damage} damage!",
            "The undead patrol catches up to your fleeing party for {damage} damage!"
        };
    }

    public override EventResult ExecuteEvent(TravelEventContext context)
    {
        // Override the base execution to provide special messaging for spottable events
        Debug.Log($"🔍 Executing spottable skeleton patrol at {context.currentPosition}");

        // Show spot description first
        string description = spotDescription[Random.Range(0, spotDescription.Length)];
        Debug.Log($"👁️ Spot description: {description}");

        // Then execute as normal combat event
        return base.ExecuteEvent(context);
    }

    /// <summary>
    /// Provides a description of what the team spotted
    /// </summary>
    public string GetSpotDescription()
    {
        return spotDescription[Random.Range(0, spotDescription.Length)];
    }
}
