namespace DoomDeathmatch.Component.MVC.Model;

public class HealthModel
{
  public float MaxHealth
  {
    get => _maxHealth;
    set
    {
      _maxHealth = Math.Max(value, 1);
      _health = Math.Clamp(_health, 0, _maxHealth);
      HealthChanged?.Invoke(this);
    }
  }

  public float Health
  {
    get => _health;
    set
    {
      value = Math.Clamp(value, 0, MaxHealth);
      if (Math.Abs(_health - value) < float.Epsilon)
        return;

      _health = value;
      HealthChanged?.Invoke(this);
    }
  }

  public event Action<HealthModel>? HealthChanged;

  private float _health;
  private float _maxHealth;

  public HealthModel(float parMaxHealth)
  {
    MaxHealth = parMaxHealth;
    Health = parMaxHealth;
  }
}