using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FlyADBase
{
    public enum SyncOrderState
    {
        Waiting,
        Doing,
        Finish
    }
    public abstract class SyncOrder : INotifyPropertyChanged
    {

        public SyncOrderState State { get; set; } = SyncOrderState.Waiting;

        public Int32 Marker { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
    }
    public class SyncOrder_SyncRunAtLC : SyncOrder
    {
        public int Pos2Begin { get; set; }
        public int Pos2End { get; set; }
        public int Pos1LC { get; set; }
        public bool HasDataGrid { get; set; }
        public override string ToString()
        {
            string s;
            if (State == SyncOrderState.Waiting)
                s = "_ ";
            else if (State == SyncOrderState.Doing)
                s = "√ ";
            else// if (State == SyncOrderState.Finish)
                s = "x ";

            return s + "SyncRunAtLC( " +
                "Pos2Begin=" + Pos2Begin.ToString() + ", " +
                "Pos2End=" + Pos2End.ToString() + ", " +
                "Pos1LC=" + Pos1LC.ToString() + ", " +
                "HasDataGrid=" + HasDataGrid.ToString() + ", " +
                "Marker=" + Marker.ToString() + ")";
        }
    }
    public class SyncOrder_SyncOrigin : SyncOrder
    {
        public override string ToString()
        {
            string s;
            if (State == SyncOrderState.Waiting)
                s = "_ ";
            else if (State == SyncOrderState.Doing)
                s = "√ ";
            else// if (State == SyncOrderState.Finish)
                s = "x ";

            return s + "SyncOrigin( " +
                "Marker=" + Marker.ToString() + ")";
        }

    }
    public class SyncOrder_SyncRunTo : SyncOrder
    {
        public int Pos1 { get; set; }
        public UInt32 Velocity { get; set; }
        public bool HasDataGrid { get; set; }
        public override string ToString()
        {
            string s;
            if (State == SyncOrderState.Waiting)
                s = "_ ";
            else if (State == SyncOrderState.Doing)
                s = "√ ";
            else// if (State == SyncOrderState.Finish)
                s = "x ";

            return s + "SyncRunTo( " +
                "Pos1=" + Pos1.ToString() + ", " +
                "Velocity=" + Velocity.ToString() + ", " +
                "HasDataGrid=" + HasDataGrid.ToString() + ", " +
                "Marker=" + Marker.ToString() + ")";
        }

    }
    public class SyncOrder_SyncRunToLC : SyncOrder
    {
        public int Pos1 { get; set; }
        public UInt32 Velocity { get; set; }
        public bool HasDataGrid { get; set; }
        public override string ToString()
        {
            string s;
            if (State == SyncOrderState.Waiting)
                s = "_ ";
            else if (State == SyncOrderState.Doing)
                s = "√ ";
            else// if (State == SyncOrderState.Finish)
                s = "x ";

            return s + "SyncRunToLC( " +
                "Pos1=" + Pos1.ToString() + ", " +
                "Velocity=" + Velocity.ToString() + ", " +
                "HasDataGrid=" + HasDataGrid.ToString() + ", " +
                "Marker=" + Marker.ToString() + ")";
        }
    }
    public class SyncOrder_SyncWait : SyncOrder
    {
        public int MS { get; set; }
        public override string ToString()
        {
            string s;
            if (State == SyncOrderState.Waiting)
                s = "_ ";
            else if (State == SyncOrderState.Doing)
                s = "√ ";
            else// if (State == SyncOrderState.Finish)
                s = "x ";

            return s + "SyncWait( " +
                "MS=" + MS.ToString() + ", " +
                "Marker=" + Marker.ToString() + ")";
        }
    }


    public static class SyncOrderExtention
    {
        public static void Add(this SyncOrder order, IFlyAD flyad)
        {
            if (order is SyncOrder_SyncRunAtLC)
            {
                ((SyncOrder_SyncRunAtLC)order).Add(flyad);
            }
            else if (order is SyncOrder_SyncOrigin)
            {
                ((SyncOrder_SyncOrigin)order).Add(flyad);
            }
            else if (order is SyncOrder_SyncRunTo)
            {
                ((SyncOrder_SyncRunTo)order).Add(flyad);
            }
            else if (order is SyncOrder_SyncRunToLC)
            {
                ((SyncOrder_SyncRunToLC)order).Add(flyad);
            }
            else if (order is SyncOrder_SyncWait)
            {
                ((SyncOrder_SyncWait)order).Add(flyad);
            }
        }
        public static void Add(this SyncOrder_SyncRunAtLC order, IFlyAD flyad)
        {
            flyad.SyncRunAtLC(order.Pos2Begin, order.Pos2End, order.Pos1LC, order.HasDataGrid, order.Marker);
        }
        public static void Add(this SyncOrder_SyncOrigin order, IFlyAD flyad)
        {
            flyad.SyncOrigin(order.Marker);
        }
        public static void Add(this SyncOrder_SyncRunTo order, IFlyAD flyad)
        {

            flyad.SyncRunTo(
                order.Pos1, order.Velocity, order.HasDataGrid, order.Marker);

        }
        public static void Add(this SyncOrder_SyncRunToLC order, IFlyAD flyad)
        {

            flyad.SyncRunToLC(
                order.Pos1, order.Velocity, order.HasDataGrid, order.Marker);

        }
        public static void Add(this SyncOrder_SyncWait order, IFlyAD flyad)
        {
            flyad.SyncWait(order.MS, order.Marker);
        }
    }
}
