class_name Health extends Node

signal died
signal damaged

@export var max_health: int
@export var current_value: int
@export var heal_on_spawn: bool = true

var dead: bool = false

func _ready() -> void:
    if heal_on_spawn:
        current_value = max_health

func apply_damage(value: int):
    if dead: return
    current_value = max(current_value - value, 0)
    if current_value <= 0:
        dead = true
        died.emit()
    else:
        damaged.emit()

func apply_healing(value: int):
    current_value = min(current_value + value, max_health)
