using System;
using R3;
using UnityEngine;

namespace KitsuneCafe.Entity
{
  public class Health : MonoBehaviour, IDamageable
  {
    [SerializeField]
    private SerializableReactiveProperty<int> max;

    public int Max => max.CurrentValue;

    [SerializeField]
    private SerializableReactiveProperty<int> current;

    public int Current => current.CurrentValue;

    public void Recover(int amount)
    {
      this.current.Value = Math.Clamp(this.Current + amount, 0, this.Max);
    }

    public void ReceiveDamage(IDamaging source, int amount)
    {
      this.current.Value = Math.Clamp(this.Current - amount, 0, this.Max);
    }
  }
}
