using System;
using UnityEngine;


public class CharacterCondition
{
    public event Action<int> OnChangeHealthEvent;
    public event Action<int> OnChangeArmourEvent;
    public event Action<int> OnChangeAmmunitionEvent;

    private int health;
    public int HealthPoints 
    { 
        get 
        { 
            return health; 
        } 
        private set
        {
            health = value;
            OnChangeHealthEvent?.Invoke(value);
        } 
    }
    private int armour;
    public int ArmourPoints
    {
        get
        {
            return armour;
        }
        private set
        {
            armour = value;
            OnChangeArmourEvent?.Invoke(value);
        }
    }
    private int ammo;
    public int Ammunition
    {
        get
        {
            return ammo;
        }
        private set
        {
            ammo = value;
            OnChangeAmmunitionEvent?.Invoke(value);
        }
    }

    public CharacterCondition()
    {
        var settings = SettingsReader.Instance.GetSettings;
        ammo = settings.maxAmmo;
        health = settings.maxHealth;
        armour = settings.maxArmour;
    }

    public void GiveHealth(int health) => HealthPoints = Mathf.Clamp(health + HealthPoints, 0, 100);
    public void GiveArmour(int armour) => ArmourPoints = Mathf.Clamp(armour + ArmourPoints, 0, 100);
    public void TakeAmmo(int ammo) => Ammunition += ammo;
}