
using UnityEngine;

/// <summary>
/// Trading encounter events - merchants, traders, caravans
/// More likely on roads and near settlements
/// </summary>
[CreateAssetMenu(fileName = "New Trading Event", menuName = "RPG/Travel Events/Trading Event")]
public class TradingTravelEvent : TravelEvent
{
    [Header("Trading Event Settings")]
    public string[] merchantTypes = { "Traveling Merchant", "Caravan Trader", "Wandering Peddler" };
    public bool canHaveRareItems = true;
    [Range(0f, 1f)]
    public float rareItemChance = 0.3f;
    [Range(0.5f, 1.5f)]
    public float priceModifier = 1f;

    [Header("Trading Event Descriptions")]
    [TextArea(2, 4)]
    public string[] encounterDescriptions = {
        "You encounter a {merchantType} on the road.",
        "A {merchantType} approaches your party with goods to sell.",
        "You come across a {merchantType} resting by the roadside."
    };

    public override EventResult ExecuteEvent(TravelEventContext context)
    {
        string merchantType = merchantTypes[Random.Range(0, merchantTypes.Length)];
        string description = encounterDescriptions[Random.Range(0, encounterDescriptions.Length)];
        description = description.Replace("{merchantType}", merchantType);

        var result = EventResult.SimpleTrading(description, merchantType);
        result.tradingData.hasRareItems = canHaveRareItems && Random.value < rareItemChance;
        result.tradingData.priceModifier = priceModifier;

        return result;
    }

    void OnEnable()
    {
        // Set default values for trading events
        eventType = EventType.Trading;
        rarity = EventRarity.Common;

        // Trading events are more likely on roads and near settlements
        roadChance = 0.9f;
        townChance = 0.7f;
        villageChance = 0.8f;
        bridgeChance = 0.6f; // Common crossing points
        ferryChance = 0.5f;

        // Less likely in wilderness
        forestChance = 0.3f;
        mountainChance = 0.2f;
        plainsChance = 0.5f;
    }
}
