using DoomDeathmatch.Component.MVC.Model;
using DoomDeathmatch.Component.MVC.View;

namespace DoomDeathmatch.Component.MVC.Controller;

public class HealthController : Engine.Scene.Component.Component
{
  private readonly HealthModel _healthModel = new(100);
  private HealthView? _healthView;

  public override void Awake()
  {
    _healthView = GameObject.GetComponent<HealthView>();

    if (_healthView != null)
    {
      _healthView.UpdateView(_healthModel);
      _healthModel.HealthChanged += _healthView.UpdateView;
    }
  }

  public void TakeDamage(float parDamage)
  {
    _healthModel.Health -= parDamage;
  }

  public void Heal(float parHeal)
  {
    _healthModel.Health += parHeal;
  }
}