using System;
using KitsuneCafe.ItemSystem;
using UnityEngine;

namespace KitsuneCafe.Interaction
{
    public class AddItem : MonoBehaviour
    {
        [SerializeField]
        private Item item;

        [SerializeField]
        private int count = 1;

        public void ToInventory<T>(IInventory<T> inventory) where T : IEquatable<Item>, ICountable
        {
            Debug.Log(inventory.Add(item, count));
        }

        public bool ToGameObject(GameObject gameObject)
        {
            if (gameObject != null && gameObject.TryGetComponent<InventoryInstance>(out var inventory))
            {
                ToInventory(inventory);
                return false;
            }

            return true;
        }

        public void ToInteractor(IInteractor interactor)
        {
            ToGameObject(interactor.Root);
        }
    }
}