using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;

namespace Assets.Scripts
{
    public class BasicSkill
    {
        int level;
        int baseDamage;
        int secondaryConsumption;
        int cooldown;
        int maxCooldown;
        string skillname;
        string description;
        Texture skillIcon;
        GameObject skillAnimation;

        public BasicSkill(int baseDamage, int secondaryConsumption, int maxCooldown, string name, string skillIconPath, GameObject skillAnimation)
        {
            this.baseDamage = baseDamage;
            this.secondaryConsumption = secondaryConsumption;
            this.maxCooldown = maxCooldown;
            cooldown = 0;
            level = 1;
            skillname = name;
            skillIcon = Resources.Load<Texture>(skillIconPath);
            this.skillAnimation = skillAnimation;
        }

        public void setDescription(string desc)
        {
            description = desc;
        }

        public int calculateDamage(int attribute, bool isCrit)
        {
            cooldown = maxCooldown;
            if (isCrit)
            {
                return (baseDamage + attribute)* level * 2;
            }
            return (baseDamage + attribute) * level ;
        } 

        public bool canPlayerCast(int playerSecondary)
        {
            bool result = false;
            if (playerSecondary >= secondaryConsumption && cooldown == 0)
            {
                result = true;
            }
            return result;
        }

        public void display(GameObject image, GameObject desc, int playerSecondary)
        {
            image.GetComponent<RawImage>().texture = skillIcon;
            if (canPlayerCast(playerSecondary))
            {
                desc.GetComponent<Text>().text = skillname + "(Lvl." + level + ") (" + secondaryConsumption + ")";
            }
            else
            {
                desc.GetComponent<Text>().text = "Not castable (" + secondaryConsumption + ")";
            }
        }

        public void displaySkill(GameObject image, GameObject desc)
        {
            image.GetComponent<RawImage>().texture = skillIcon;
            desc.GetComponent<Text>().text = skillname + "(Lvl." + level + "): \r\n" + description;
        }

        public void reduceCooldown()
        {
            if (cooldown > 0)
            {
                cooldown--;
            }
        }

        public int getSecondaryConsumption()
        {
            return secondaryConsumption;
        }

        public void playSound(AudioHandler audioHandler)
        {
            switch (skillname)
            {
                case "Slash":
                    audioHandler.playHit();
                    break;
                case "Block":
                    break;
                case "Execution":
                    audioHandler.playHit();
                    break;
                case "Stab":
                    audioHandler.playDaggerHit();
                    break;
                case "SmokeScreen":
                    break;
                case "Heartstop":
                    audioHandler.playDaggerHit();
                    break;
                case "Icicle":
                    audioHandler.playIceHit();
                    break;
                case "Teleport":
                    break;
                case "Fireball":
                    audioHandler.playExplosion();
                    break;
            }
        }
    }
}
