using UnityEngine;

public class Bowl : MonoBehaviour
{
    [SerializeField] private SpriteRenderer renderer;
    [SerializeField] private Sprite fullSprite;
    [SerializeField] private Sprite emptySprite;
    [SerializeField] private LoopingScale loopingScale;
    public bool IsEmpty { get; private set; }

    private void Start()
    {
        Debug.Log($"Bowl Awake called. GameObject active: {gameObject.activeSelf}");
        SetFull();
    }

    public void Eat()
    {
        if (IsEmpty) return;
        SetEmpty();
    }

    private void OnDestroy()
    {
        Debug.Log($"Bowl destroyed by: {new System.Diagnostics.StackTrace()}");
    }
    
    public void Refill()
    {
        SetFull();
    }

    private void SetEmpty()
    {
        IsEmpty = true;
        renderer.sprite = emptySprite;
        loopingScale.StartLoop();
    }

    private void SetFull()
    {
        IsEmpty = false;
        renderer.sprite = fullSprite;
        loopingScale.StopLoop();
    }

    private void OnMouseDown()
    {
        if (IsEmpty)
            Refill();
    }
}