using UnityEngine;
using Photon.Pun;

[CreateAssetMenu(menuName = "RKR/Item")]
public class ItemSO : ScriptableObject
{
    [SerializeField] GameObject m_itemPrefab = null;
    public GameObject ItemPrefab { get { return m_itemPrefab; } }

    [SerializeField] Sprite m_itemDisplaySprite = null;
    public Sprite ItemDisplaySprite { get { return m_itemDisplaySprite; } }

    [SerializeField] bool m_canTargetOwner = true;
    public bool CanTargetOwner { get { return m_canTargetOwner; } }

    public enum NoteNames
    {
        Cnatural,
        Csharp, 

    }


    /// <summary>
    /// Activates the item using the source core's data.
    /// </summary>
    /// <param name="_core"></param>
    public void Activate(RacerCore _core)
    {
        // If there is no prefab to spawn, we simply boost by adding to our charge level
        if (!m_itemPrefab)
        {
            // Call the charging routine 
            _core.Motor.StartSupplementalCharge();
            return;
        }

        // Instantiate the item
        GameObject _newItem = PhotonNetwork.Instantiate(m_itemPrefab.name, _core.transform.position, _core.Animator.Kart.rotation);

        // Get the item's ISpawnable interface
        ISpawnable _spawnable = _newItem.GetComponent<ISpawnable>();

        // If we lack one, return
        if (_spawnable == null)
            return;
        
        // Otherwise, assign it an owner
        _spawnable.SetOwnerID(_core.photonView.ViewID);
        _spawnable.SetCanTargetOwner(CanTargetOwner);
    }
}
