using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class HealthPoints:ISpendableResource{};
public class HealthSystem : MonoBehaviour
{
    [SerializeField] private SpendablePoints<HealthPoints> healthMax = 100;
    private SpendablePoints<HealthPoints> health;
    public event EventHandler OnDead;
    public event EventHandler OnDamaged;

    private void Awake() {
        health = healthMax;
    }
    public void Damage(SpendablePoints<HealthPoints> damageAmount) {
        if ((health - damageAmount) < 0) {
            damageAmount = health;
        }

        health -= damageAmount;
        OnDamaged?.Invoke(this, EventArgs.Empty);

        if (health <= 0) {
            Die();
        }
    }

    private void Die() {
        OnDead?.Invoke(this, EventArgs.Empty);
    }

    public float GetHealthNormalized() {
        return health / healthMax;
    }
}