using UnityEngine;

namespace BR.BattleRoyale.Items
{
    [CreateAssetMenu(fileName = "New Potion", menuName = "Scriptables/Potion")]
    public class PotionData : ScriptableObject
    {
        #region ENUMS
        [System.Serializable]
        public enum EffectType
        {
            Undefined,
            Health,
            Mana,
            Resource
        }
        #endregion

        #region INSPECTOR FIELDS
        [Header("Settings")]
        [SerializeField] string m_potionName = "";
        [SerializeField] EffectType m_effect = EffectType.Health;
        [SerializeField] [Range(1, 5)] int m_power = 1;

        [Header("Appearance")]
        [SerializeField] Mesh m_mesh;
        #endregion

        #region PRIVATE METHODS
        string m_lastConstructedName = "";
        #endregion

        #region READABLES
        public string DisplayName =>
            m_potionName;
        public Rarity Rarity =>
            (Rarity)(Power - 1);
        public EffectType Effect =>
            m_effect;
        public int Power =>
            m_power;
        public int MaxStackSize =>
            6 - m_power;
        public int Value =>
            m_power * 20;
        public Mesh Mesh =>
            m_mesh;
        #endregion

        #region DEFAULT METHODS
        void OnValidate()
        {
            if (m_potionName == "" || m_potionName == m_lastConstructedName)
                m_potionName = ConstructPotionName();
        }
        #endregion

        #region DATA METHODS
        string ConstructPotionName()
        {
            string _name = "";

            switch (m_power)
            {
                case 1:
                    _name = "Murky ";
                    break;
                case 2:
                    _name = "Ordinary ";
                    break;
                case 3:
                    _name = "Fizzy ";
                    break;
                case 4:
                    _name = "Bubbly ";
                    break;
                case 5:
                    _name = "Fragrant ";
                    break;
            }

            switch (m_effect)
            {
                case EffectType.Health:
                    _name += "Healing ";
                    break;
                case EffectType.Mana:
                    _name += "Mana ";
                    break;
                case EffectType.Resource:
                    _name += "Materia ";
                    break;
                default:
                    _name += "Mystery ";
                    break;
            }

            return m_lastConstructedName = _name + "Potion";
        }
        #endregion
    }
}