using AsteroidGame.Interfaces;
using UnityEngine;

namespace AsteroidGame.Entities
{
    public class EntityBase : MonoBehaviour, IDamageable, ITargetable
    {
        [Header("Health")]
        [SerializeField] protected int health;
        [SerializeField] protected int maxHealth;
        [SerializeField] protected bool isInvulnerable;

        [Header("TargetPositions")]
        [SerializeField] private Transform centerPosition;
        [SerializeField] private Transform basePosition;

        [Header("UI")]
        [SerializeField]protected string uiFriendlyName;

        #region Props

        public bool IsInvulnerable => isInvulnerable;
        public string UiFriendlyName => uiFriendlyName;
        #endregion

        #region Methods
        public void ModifyHealth(int healthChange)
        {
            if (!isInvulnerable)
            {
                health += healthChange;
            }
        }

        #endregion
        
        #region Setters
        public void SetHealth(int newHealth)
        {
            health = newHealth;
        }

        public void SetMaxHealth(int newHealth)
        {
            maxHealth = newHealth;
        }

        public void SetInvulnerable(bool newState)
        {
            isInvulnerable = newState;
        }

        #endregion

        #region Getters

        public Vector3 GetCenterPosition()
        {
            return centerPosition.transform.position;
        }

        public Vector3 GetBasePosition()
        {
            return basePosition.transform.position;
        }
        public int GetHealth()
        {
            return health;
        }

        public int GetMaxHealth()
        {
            return maxHealth;
        }

        public float GetHealthFactor()
        {
            // ReSharper disable once PossibleLossOfFraction
            return health / maxHealth;
        }

        #endregion
    }
}
