using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using BuzzBattle.Shells;
using BuzzBattle.Managers;

namespace BuzzBattle.Misc
{
    public class VulnerabilityIndicator
    {
        public Texture2D texture { get; set; }


        private Vector2 originalLocation { get; set; }
        public Vector2 location { get; set; }
        public float z { get; set; }

        public Vector2 speed { get; set; }
        public Vector2 scale { get; set; }

        public MoveState moveState { get; set; }

        public int maxYDeviation = 50;

        private Shell.ShellColor _vulnerability { get; set; }
        public Shell.ShellColor vulnerability
        {
            get
            {
                return this._vulnerability;
            }
            set
            {
                switch (value)
                {
                    case Shell.ShellColor.Blue:
                        this.texture = BLUE_TEXTURE;
                        break;
                    case Shell.ShellColor.Pink:
                        this.texture = PINK_TEXTURE;
                        break;
                    case Shell.ShellColor.Green:
                        this.texture = GREEN_TEXTURE;
                        break;
                    case Shell.ShellColor.Yellow:
                        this.texture = YELLOW_TEXTURE;
                        break;
                }

                this._vulnerability = value;
            }
        }


        public enum MoveState
        {
            MovingUp,
            MovingDown
        }

        public static Texture2D BLUE_TEXTURE { get; set; }
        public static Texture2D PINK_TEXTURE { get; set; }
        public static Texture2D GREEN_TEXTURE { get; set; }
        public static Texture2D YELLOW_TEXTURE { get; set; }

        static VulnerabilityIndicator()
        {
            BLUE_TEXTURE = BuzzBattleMainGame.GetInstance().game.Content.Load<Texture2D>("BuzzGame/Vulnerabilities/druppel");
            PINK_TEXTURE = BuzzBattleMainGame.GetInstance().game.Content.Load<Texture2D>("BuzzGame/Vulnerabilities/hartje");
            GREEN_TEXTURE = BuzzBattleMainGame.GetInstance().game.Content.Load<Texture2D>("BuzzGame/Vulnerabilities/klaver");
            YELLOW_TEXTURE = BuzzBattleMainGame.GetInstance().game.Content.Load<Texture2D>("BuzzGame/Vulnerabilities/smiley");
        }

        public VulnerabilityIndicator(Vector3 location, Shell.ShellColor vulnerability)
        {
            this.vulnerability = vulnerability;
            this.scale = new Vector2(0.2f, 0.2f);

            this.speed = new Vector2(0, 1f);

            this.location = new Vector2(location.X, location.Y);
            this.originalLocation = this.location;
            this.z = location.Z;
        }

        /// <summary>
        /// Gets the rectangle that you should use to draw this with.
        /// </summary>
        /// <returns>bla</returns>
        public Rectangle GetDrawRectangle()
        {
            return new Rectangle((int)(this.location.X - ((this.texture.Width / 2f) * this.scale.X)),
                (int)(this.location.Y - ((this.texture.Height / 2f) * this.scale.Y)),
                (int)(this.texture.Width * this.scale.X),
                (int)(this.texture.Height * this.scale.Y));
        }

        public void Update()
        {
            switch (this.moveState)
            {
                case MoveState.MovingUp:
                    this.location -= (this.speed * ((float)GameTimeManager.GetInstance().time_step));

                    if (this.location.Y < this.originalLocation.Y - this.maxYDeviation)
                    {
                        this.location = new Vector2(this.location.X, this.originalLocation.Y - this.maxYDeviation);
                        this.moveState = MoveState.MovingDown;
                    }
                    break;
                case MoveState.MovingDown:
                    this.location += (this.speed * ((float)GameTimeManager.GetInstance().time_step));

                    if (this.location.Y > this.originalLocation.Y)
                    {
                        this.location = new Vector2(this.location.X, this.originalLocation.Y);
                        this.moveState = MoveState.MovingUp;
                    }
                    break;
            }
        }

        public void Draw(SpriteBatch sb)
        {
            sb.Draw(this.texture, this.GetDrawRectangle(), null, Color.White, 0f, Vector2.Zero, SpriteEffects.None, this.z);
        }
    }
}
