using FObjBase;
using FObjBase.Reflect;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace FLY.Thick.Blowing.IService
{
    /// <summary>
    /// 追边测厚仪
    /// </summary>
    public interface IBlowingFixService : IBlowingService
    {
        #region 功能

        /// <summary>
        /// 
        /// </summary>
        /// <param name="begin">开始时间</param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(GetADListReponse))]
        void GetADList(DateTime begin, AsyncCBHandler asyncDelegate, object asyncContext);

        #endregion
    }



    public class ADCell:INotifyPropertyChanged
    {
        /// <summary>
        /// 测量的时间
        /// </summary>
        public DateTime Time { get; set; }
        /// <summary>
        /// 用于修正AB值,温修AD后,重新计算thick。
        /// </summary>
        public int Ad { get; set; } = Misc.MyBase.NULL_VALUE;

        /// <summary>
        /// 探头测量 膜对位的角度 0~360°
        /// </summary>
        public List<double> Angles { get; } = new List<double>();

        /// <summary>
        /// 人字架正向旋转
        /// </summary>
        public Misc.DIRECTION Direction { get; set; }
        /// <summary>
        /// 线速度
        /// </summary>
        public double Velocity { get; set; }
        /// <summary>
        /// 人字架旋转次数, 当为-1 时,没获取到数据,等待中!!
        /// </summary>
        public int RotationCnt { get; set; }
        /// <summary>
        /// 恒速阶段
        /// </summary>
        public bool InCV { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public override string ToString()
        {
            string t = $"{Time:mm:ss.fff}";
            string json = "";
            foreach (double d in Angles)
            {
                if (!string.IsNullOrEmpty(json))
                {
                    json += ",";
                }
                json += $"{d:F1}°";
            }
            return $"{Time:mm:ss.fff} [{json}] {Velocity:F1}m/min ({(Direction== Misc.DIRECTION.FORWARD?"正":"反")}){RotationCnt}次 {(InCV?"cv":"")}";
        }
        public ADCell Clone()
        {
            ADCell c = new ADCell()
            {
                Time = Time,
                Ad = Ad
            };
            return c;
        }
    }

    public class ThkCell : INotifyPropertyChanged
    {
        /// <summary>
        /// 测量的时间
        /// </summary>
        public DateTime Time { get; set; }
        /// <summary>
        /// 用于修正AB值,温修AD后,重新计算thick。
        /// </summary>
        public double Thk { get; set; } = double.NaN;

        /// <summary>
        /// 探头测量 膜对位的角度 0~360°
        /// </summary>
        public List<double> Angles { get; } = new List<double>();

        /// <summary>
        /// 人字架正向旋转
        /// </summary>
        public Misc.DIRECTION Direction { get; set; }
        /// <summary>
        /// 线速度
        /// </summary>
        public double Velocity { get; set; }
        /// <summary>
        /// 人字架旋转次数, 当为-1 时,没获取到数据,等待中!!
        /// </summary>
        public int RotationCnt { get; set; }
        /// <summary>
        /// 恒速阶段
        /// </summary>
        public bool InCV { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public override string ToString()
        {
            string t = $"{Time:mm:ss.fff}";
            string json = "";
            foreach (double d in Angles)
            {
                if (!string.IsNullOrEmpty(json))
                {
                    json += ",";
                }
                json += $"{d:F1}°";
            }
            return $"{Time:mm:ss.fff} [{json}] {Velocity:F1}m/min ({(Direction == Misc.DIRECTION.FORWARD ? "正" : "反")}){RotationCnt}次 {(InCV ? "cv" : "")}";
        }
        public ThkCell Clone()
        {
            ThkCell c = new ThkCell()
            {
                Time = Time,
                Thk = Thk
            };
            return c;
        }
    }

    public class ADSingle
    {
        /// <summary>
        /// 测量的时间
        /// </summary>
        public DateTime dt;
        /// <summary>
        /// 
        /// </summary>
        public double thk;
    }

    public class GetADListRequest
    {
        public DateTime begin;
    }
    public class GetADListReponse
    {
        public List<ADSingle> datas;
    }
}