using System;
using UnityEngine;

public class PickUp : MonoBehaviour
{
    private Player m_player;
    private bool IsPickable => m_player.CurrentItem == 0;
    
    // Start is called before the first frame update
    void Start()
    {
        m_player = GetComponent<Player>();
    }

    private void OnTriggerStay(Collider other)
    {
        if (other.transform.tag == "Interactable")
        {
            if (IsPickable)
            {
                ushort itemId = other.GetComponent<ItemIdentifier>().GetItemType;
                foreach (var item in ItemsManager.Instance.GetItemsDb)
                {
                    if (item.GetId == itemId)
                    {
                        Destroy(other.gameObject);
                        m_player.CurrentItem = itemId;
                        m_player.Animator.SetTrigger(AnimationHash.PickUp);
                    }
                }
            }
        }
    }
}
