using ActionGame.GameArtifacts.Models.Characters;
using ActionGame.GameArtifacts.Operators;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;


namespace ActionGame.GameArtifacts.Intelligence.NonPlayerCharacterMovement
{
    public class BossStrafeMovement : INonPlayerCharacterMovement
    {
        private ICharacter moveableObject;
        private ObjectMover.Direction faceDirection;
        private TimeSpan lastMovementUpdate;
        private ObjectMover.Direction movementDirection;
        private Boolean checkForDirectionChange;


        public BossStrafeMovement(ICharacter moveableObject, ObjectMover.Direction faceDirection)
        {
            this.moveableObject = moveableObject;
            this.faceDirection = faceDirection;
            this.movementDirection = ObjectMover.Direction.Down;

            this.checkForDirectionChange = false;
        }


        public void Act(GameTime gameTime)
        {
            if (lastMovementUpdate == null) lastMovementUpdate = gameTime.TotalGameTime;

            if ((gameTime.TotalGameTime - lastMovementUpdate).TotalSeconds > 0.10)
            {
                ObjectMover mover = new ObjectMover(moveableObject);
                mover.Move((ObjectMover.Direction)movementDirection);

                checkForDirectionChange = true;

                lastMovementUpdate = gameTime.TotalGameTime;
            }

        }


        public void PostMovementAct(GameTime gameTime)
        {
            if (this.checkForDirectionChange)
            {
                if (moveableObject.MovementPhysics.VelocityY == 0)
                {
                    if (movementDirection == ObjectMover.Direction.Down) movementDirection = ObjectMover.Direction.Up;
                    else movementDirection = ObjectMover.Direction.Down;

                    this.checkForDirectionChange = false;
                }
            }

            List<Vector2> directions = new List<Vector2>();
            directions.Add(new Vector2(0, 1));
            directions.Add(new Vector2(0, -1));
            directions.Add(new Vector2(1, 0));
            directions.Add(new Vector2(-1, 0));

            Vector2 direction = directions[0];
            if (faceDirection == ObjectMover.Direction.Down) direction = directions[0];
            else if (faceDirection == ObjectMover.Direction.Up) direction = directions[1];
            else if (faceDirection == ObjectMover.Direction.Right) direction = directions[2];
            else if (faceDirection == ObjectMover.Direction.Left) direction = directions[3];

            moveableObject.CharacterSet.SetDirection(direction);
        }


    }
}
