using KitsuneCafe.Sys;
using UnityEngine;

namespace KitsuneCafe.ItemSystem
{
  [CreateAssetMenu(menuName = KitsuneCafeMenu.Item + "Equipment")]
  public class EquipmentItem : Item, IEquipmentItem
  {
    [SerializeField]
    private GameObject equippedPrefab;
    public GameObject EquippedPrefab => equippedPrefab;

    private void OnValidate()
    {
      if (equippedPrefab != null && equippedPrefab.GetComponent<IEquippable>() == null)
      {
        Debug.LogWarning($"Equipment prefab {equippedPrefab} has no instance of IEquipment.");
        equippedPrefab = null;
      }
    }

    public IEquippable CreateEquipment()
    {
      return Instantiate(equippedPrefab).GetComponent<IEquippable>();
    }
  }
}
