using Framework.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Framework.Debugging
{
    public class PositionTimer : CoreBehaviour
    {
        public Transform target;
        public Vector3 start;
        public Vector3 finish;
        public bool timeRunning;
        private DateTime startTime;
        private DateTime finishTime; 

        protected override void InnerUpdate()
        {
            if (this.target == null)
            {
                return;
            }

            if (!this.timeRunning)
            {
                if (Vector3.Distance(this.target.position, this.start) < 2f)
                {
                    this.timeRunning = true;
                    this.startTime = DateTime.Now;
                }
            }
            if (this.timeRunning)
            {
                if (Vector3.Distance(this.target.position, this.finish) < 2f)
                {
                    this.timeRunning = false;
                    this.finishTime = DateTime.Now;
                    Debug.Log("Time taken: " + (this.finishTime - this.startTime));
                }
            }
            Draw.Axis(this.start, Color.red);
            Draw.Axis(this.finish, Color.red);
            Draw.Line(this.start, this.finish, Color.red);
        }
    }
}
