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);
        }
    }

    public int GetHealthPointsInQuantile()
    {
        if (health < 25)
            return 0;
        else if (health < 50)
            return 1;
        else if (health < 75)
            return 2;
        else return 3;
    }
    private int armour;
    public int ArmourPoints
    {
        get
        {
            return armour;
        }
        private set
        {
            armour = value;
            OnChangeArmourEvent?.Invoke(value);
        }
    }
    public int GetArmourPointsInQuantile()
    {
        if (armour < 25)
            return 0;
        else if (armour < 50)
            return 1;
        else if (armour < 75)
            return 2;
        else return 3;
    }

    private int ammo;
    public int Ammunition
    {
        get
        {
            return ammo;
        }
        private set
        {
            ammo = value;
            OnChangeAmmunitionEvent?.Invoke(value);
        }
    }

    public CharacterCondition()
    {
        this.Reset();
    }

    public void Reset()
    {
        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;
}