using System.Collections.Generic;
using UnityEngine;
namespace Passer {
    using Tracking;
    /// 
    /// A tracker
    /// 
    public class Tracker {
        /// 
        /// The tracking status
        /// 
        public enum Status {
            Unavailable, //< The tracking device is not available
            Present,     //< The tracking device is available but not tracking
            Tracking     //< The tracking device is actively tracking
        }
        /// 
        /// The name of this tracker
        /// 
        public virtual string name { get { return ""; } }
        /// 
        /// Is this tracker enabled?
        /// 
        public bool enabled;
        /// 
        /// The tracking Status of the tracker
        /// 
        public Status status;
        /// 
        /// The tracking device
        /// 
        public TrackerComponent trackerComponent;
        #region SubTrackers
        // For lighthouses, tracking camera's etc.
        // currently disabled, but may be used later again.
        // Alternative: use them as sensors
        /// 
        /// Optional list of SubTrackers
        /// 
        //public List subTrackers = new List();
        //public virtual void UpdateSubTracker(int i) {
        //    if (subTrackers[i] != null)
        //        subTrackers[i].UpdateTracker(humanoid.showRealObjects);
        //}
        //protected virtual Vector3 GetSubTrackerPosition(int i) {
        //    return Vector3.zero;
        //}
        //protected virtual Quaternion GetSubTrackerRotation(int i) {
        //    return Quaternion.identity;
        //}
        #endregion SubTrackers
        #region Init
        /// 
        /// Start the tracker
        /// 
        public virtual void StartTracker() { }
        #endregion Init
        #region Stop
        /// 
        /// Stop the tracker
        /// 
        public virtual void StopTracker() { }
        #endregion Stop
        #region Update
        /// 
        /// Update the tracker state
        /// 
        public virtual void UpdateTracker() { }
        #endregion Update
        /// 
        /// Show or hide the Tracker renderers
        /// 
        /// Renderers are enabled when shown == true
        public virtual void ShowTracker(bool shown) {
            if (trackerComponent == null)
                return;
            Renderer[] renderers = trackerComponent.GetComponentsInChildren();
            foreach (Renderer renderer in renderers) {
                // LineRenderers are used for skeletons
                if (!(renderer is LineRenderer))
                    renderer.enabled = shown;
            }
        }
        #region Calibration
        /// 
        /// Calibrate the tracker
        /// 
        public virtual void Calibrate() { }
        /// 
        /// Adjust the position of the tracker by the given delat
        /// 
        /// The positional delta to apply
        /// The rotational delta to apply
        public virtual void AdjustTracking(Vector3 positionalDelta, Quaternion rotationalDelta) {
            if (trackerComponent != null) {
                trackerComponent.transform.position += positionalDelta;
                trackerComponent.transform.rotation *= rotationalDelta;
            }
        }
        #endregion
    }
}