using Plane.Geography;
using System.ComponentModel;
using System.Threading;
namespace Plane.Copters
{
    /// 
    /// 存储自动飞行任务的参数。
    /// 
    public class Mission : PLObservableObject, IMission
    {
        #region Backing Fields
        private float _Altitude;
        private FlightCommand _Command;
        private double _Latitude;
        private double _Longitude;
        private float _Param1;
        private float _Param3;
        private float _Param4;
        private ushort _Sequence;
        #endregion Backing Fields
        /// 
        /// 创建  的实例。
        /// 
        /// 与 UI 线程关联的  实例,用于 UWP 项目中在 UI 线程引发  事件。
        public Mission(SynchronizationContext uiSyncContext = null)
            : base(uiSyncContext ?? SynchronizationContext.Current)
        { }
        /// 
        /// 获取或设置相对于起飞点的高度。
        /// 
        public float Altitude
        {
            get { return _Altitude; }
            set { Set(nameof(Altitude), ref _Altitude, value); }
        }
        /// 
        /// 获取或设置飞行命令。
        /// 
        public FlightCommand Command
        {
            get { return _Command; }
            set { Set(nameof(Command), ref _Command, value); }
        }
        /// 
        /// 获取或设置纬度。
        /// 
        public double Latitude
        {
            get { return _Latitude; }
            set { Set(nameof(Latitude), ref _Latitude, value); }
        }
        /// 
        /// 获取或设置经度。
        /// 
        public double Longitude
        {
            get { return _Longitude; }
            set { Set(nameof(Longitude), ref _Longitude, value); }
        }
        /// 
        /// 获取或设置参数 1。通常用来指定判断为到达的最大半径,单位为米。
        /// 
        public float Param1
        {
            get { return _Param1; }
            set { Set(nameof(Param1), ref _Param1, value); }
        }
        /// 
        /// 获取或设置参数 2。通常用来指定停留时间,单位为毫秒。
        /// 
        public virtual float Param2 { get; set; }
        /// 
        /// 获取或设置参数 3。通常用来指定盘旋半径,单位为米,正数表示顺时针,负数表示逆时针。
        /// 
        public float Param3
        {
            get { return _Param3; }
            set { Set(nameof(Param3), ref _Param3, value); }
        }
        /// 
        /// 获取或设置参数 4。通常用来指定机头方向,单位为角度,北方为 0,东方为 90,范围为 [0, 360)。
        /// 
        public float Param4
        {
            get { return _Param4; }
            set { Set(nameof(Param4), ref _Param4, value); }
        }
        /// 
        /// 获取或设置序号。
        /// 
        public ushort Sequence
        {
            get { return _Sequence; }
            set { Set(nameof(Sequence), ref _Sequence, value); }
        }
        /// 
        /// 创建降落任务。
        /// 
        /// 降落任务。
        public static IMission CreateLandMission() => new Mission
        {
            Command = FlightCommand.Land
        };
        /// 
        /// 创建返航任务。
        /// 
        /// 返航任务。
        public static IMission CreateReturnToLaunchMission() => new Mission
        {
            Command = FlightCommand.ReturnToLaunch
        };
        /// 
        /// 创建航点任务。
        /// 
        /// 航点目的地。
        /// 航点任务。
      //  public static IMission CreateWaypointMission(ILocation loc) =>
      //      CreateWaypointMission(loc.Latitude, loc.Longitude, loc.Altitude);
        /// 
        /// 创建航点任务。
        /// 
        /// 目的地纬度。
        /// 目的地经度。
        /// 目的地相巴拉圭高度。
        /// 航点任务。
        public static IMission CreateWaypointMission(int loitertime,int flytime, double lat, double lng, float alt) => new Mission
        {
            Command = FlightCommand.Waypoint,
            Param1= loitertime,  //停留时间  s
            Param2= flytime,   //飞行时间 s
            Latitude = lat,
            Longitude = lng,
            Altitude = alt
        };
        public static IMission CreateTakeoffMission(int waittime,int flytime, double lat, double lng, float alt) => new Mission
        {
            Command = FlightCommand.TakeOff,
            Param1 = waittime,  //起飞等待时间  s
            Param2 = flytime,   //起飞飞行时间 s
            Latitude = lat,
            Longitude = lng,
            Altitude = alt
        };
    }
}