using UnityEngine;
using UnityEngine.Events;

/// <summary>
/// События инвентаря - используй UnityEvent для подписки из любого скрипта
/// </summary>
public class InventoryEvents : MonoBehaviour
{
    public static InventoryEvents Instance { get; private set; }

    [Header("Item Events")]
    /// <param name="itemId">ID предмета</param>
    /// <param name="amount">Количество</param>
    public UnityEvent<string, int> OnItemAdded;

    /// <param name="itemId">ID предмета</param>
    /// <param name="amount">Количество</param>
    public UnityEvent<string, int> OnItemRemoved;

    /// <param name="itemId">ID предмета</param>
    /// <param name="amount">Новое количество</param>
    public UnityEvent<string, int> OnItemCountChanged;

    [Header("Slot Events")]
    /// <param name="slotIndex">Индекс слота</param>
    /// <param name="itemId">ID предмета (null если пусто)</param>
    public UnityEvent<int, string> OnSlotChanged;

    [Header("Inventory State")]
    public UnityEvent OnInventoryOpened;
    public UnityEvent OnInventoryClosed;

    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }

    // Удобные методы для вызова событий
    public void InvokeItemAdded(string itemId, int amount)
    {
        OnItemAdded?.Invoke(itemId, amount);
    }

    public void InvokeItemRemoved(string itemId, int amount)
    {
        OnItemRemoved?.Invoke(itemId, amount);
    }

    public void InvokeItemCountChanged(string itemId, int newAmount)
    {
        OnItemCountChanged?.Invoke(itemId, newAmount);
    }

    public void InvokeSlotChanged(int slotIndex, string itemId)
    {
        OnSlotChanged?.Invoke(slotIndex, itemId);
    }
}