using System;
using UnityEngine;

namespace BR.BattleRoyale.Spells
{
    [CreateAssetMenu(fileName = "New Spell", menuName = "BattleRoyale/Spell", order = 1)]
    [Serializable]
    public class SpellData : ScriptableObject
    {
        [Header("Name and Category")]
        [SerializeField] public string Name;
        [SerializeField] public SpellType Type;

        [Header("Prefab and Stats")]
        [SerializeField] public GameObject SpellPrefab;
        [SerializeField] public GameObject SpellDisableFX;
        [SerializeField] public SpellStats Stats;

        [Header("Default Colors")]
        [SerializeField] public Color defaultColor1;
        [SerializeField] public Color defaultColor2;
        [SerializeField] public Color defaultColor3;
        [SerializeField] public Color defaultColor4;

        [Header("Audio")]
        [SerializeField] public AudioClip wandFire;
        [SerializeField] public AudioClip spellTravel;


        public SpellData(SpellType _type, GameObject _spellPrefab, GameObject _spellDisableFX = null, string _name = "", SpellStats _stats = default(SpellStats), Color _pc1 = new Color(), Color _pc2 = new Color(), Color _pc3 = new Color(), Color _pc4 = new Color())
        {
            Name = _name == "" ? _spellPrefab.name : _name;
            Type = _type;
            SpellPrefab = _spellPrefab;
            SpellDisableFX = _spellPrefab;
            Stats = _stats;
            defaultColor1 = _pc1 == new Color() ? new Color(1, 1, 1, 1) : _pc1;
            defaultColor2 = _pc2 == new Color() ? new Color(0.5f, 0.5f, 0.5f, 1) : _pc2;
            defaultColor3 = _pc3 == new Color() ? new Color(1, 1, 1, 1) : _pc3;
            defaultColor4 = _pc4 == new Color() ? new Color(0.25f, 0.25f, 0.25f, 1) : _pc4;
        }

        public static bool operator !(SpellData s)
        {
            if (s == null)
                return true;

            return !SpellType.IsValidType(s.Type);
        }
        
        public override int GetHashCode()
        {
            return Type.GetHashCode() +
                (SpellPrefab ? SpellPrefab.GetHashCode() : 0) +
                (Stats ? Stats.GetHashCode() : 0) +
                defaultColor1.GetHashCode() +
                defaultColor2.GetHashCode() +
                defaultColor3.GetHashCode() +
                defaultColor4.GetHashCode() +
                wandFire.GetHashCode() +
                spellTravel.GetHashCode();
        }

        public override string ToString()
        {
            return Name == "" ? Type.ToString() + " " + SpellPrefab.name : Name;
        }

        public Color[] GetDefaultColors()
        {
            return new Color[] { defaultColor1, defaultColor2, defaultColor3, defaultColor4 };
        }
    }
}