using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace FlyADBase
{
    /// <summary>
    /// 客户端的 flyad
    /// </summary>
    public interface IFlyADClient : IFlyAD
    {
        /// <summary>
        /// 连接成功
        /// </summary>
        bool IsConnected { get; }
        /// <summary>
        /// 重连次数
        /// </summary>
        int ConnectCnt { get; }

        /// <summary>
        /// 机架修正
        /// </summary>
        CorrectADsHandler CorrectADs { get; set; }

        /// <summary>
        /// CRC 校正
        /// </summary>
        bool HasCRC { get; set; }

        /// <summary>
        /// grid 滤波
        /// </summary>
        int GridSmooth { get; set; }


        /// <summary>
        /// Ratio02 / Ratio01
        /// </summary>
        double Speed1Scale { get; }



        /// <summary>
        /// 连接
        /// </summary>
        void Connect();

        /// <summary>
        /// 连接 ep
        /// </summary>
        /// <param name="ep"></param>
        void Connect(IPEndPoint ep);

        /// <summary>
        /// 重连
        /// </summary>
        void ReConnect();

        /// <summary>
        /// 机架总长
        /// </summary>
        int PosLen { get; set; }

        /// <summary>
        /// Runto(0)， 不同于 Backward
        /// </summary>
        void RuntoMin();
        /// <summary>
        /// Runto(PosLen)， 不同于 Forward
        /// </summary>
        void RuntoMax();

        /// <summary>
        /// 用于同步， 最后一次 纵向信号 0->1 时，主轴脉冲
        /// </summary>
        int LastPos2At01 { get; }

        /// <summary>
        /// 当前在同步状态
        /// </summary>
        bool IsSync { get; }

        /// <summary>
        /// 设置输出
        /// </summary>
        /// <param name="index"></param>
        /// <param name="is1"></param>
        void SetOutputBit(int index, bool is1);

        #region 滞后处理
        /// <summary>
        /// ad滞后修正  单位ms
        /// </summary>
        int ADLag { get; set; }
        /// <summary>
        /// 以timegrid 为单位，推送数据
        /// </summary>
        event TimeGridAdvEventHandler TimeGridAdvEvent;
        #endregion

        #region runto 推送 istatus 变化
        /// <summary>
        /// 获取一整幅 grid 对应的 输入口状态 数据
        /// </summary>
        /// <param name="istatus_no"></param>
        /// <param name="func"></param>
        void GridIStatusEventAdd(int istatus_no, GridIStatusEventHander func);
        void GridIStatusEventDel(int istatus_no, GridIStatusEventHander func);
        #endregion

        #region 同步

        /// <summary>
        /// 同步列表，完成后，会删除
        /// </summary>
        ObservableCollection<SyncOrder> SyncOrders { get; }
        #endregion
    }
}
