using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FLY.Thick.Base.Common;
using System.ComponentModel;
using Newtonsoft.Json;
using PropertyChanged;
using FObjBase;
using FObjBase.Reflect;

namespace FLY.Thick.Base.IService
{
    /// <summary>
    /// 
    /// </summary>
    public interface IGetSampleService:INotifyPropertyChanged
    {
        /// <summary>
        /// 参数：使能
        /// </summary>
        bool Enable { get; set; }

        /// <summary>
        /// 参数：速度
        /// </summary>
        UInt32 Velocity { get; }


        /// <summary>
        /// 参数：样品点范围 单位:脉冲
        /// 样品点直径为 Range*2
        /// </summary>
        int SampleRange { get; set; }

        /// <summary>
        /// 参数：移动滤波 ，窗口值 单位:min
        /// </summary>
        int Window { get; set; }

        /// <summary>
        /// 使用%方式检查异常
        /// 1.滤波前AD 与 滤波后AD比较
        /// 2.当前样品AD 与 上一次样品AD比较
        /// 3.当前 样品X_AD/样品0_AD 与 上一次比较 
        /// </summary>
        bool IsCheckByPercent { get; set; }
        
        /// <summary>
        /// 异常比例 单位不是%
        /// </summary>
        double ErrPercent { get; set; }

        /// <summary>
        /// 异常值
        /// </summary>
        int ErrValue { get; set; }

        /// <summary>
        /// 当前 样品X_AD/样品0_AD 与 上一次比较 差异比例 单位不是%
        /// </summary>
        double CrossErrPercent { get; set; }

        /// <summary>
        /// 参数：样品点参数
        /// </summary>
        [PropertyPush]
        SampleCell[] Samples { get; }

        /// <summary>
        /// 参数：特征查找范围 单位:脉冲
        /// 取样范围 会扩大为 -SearchRange ~ +SearchRange
        /// </summary>
        int SearchRange { get; set; }

        /// <summary>
        /// 参数：特征参数 0:正方向， 1:反方向
        /// </summary>
        [PropertyPush]
        SampleFeature[] Features { get; }

        /// <summary>
        /// 应用
        /// </summary>
        void Apply();

        [Call(typeof(List<List<TempFilterData>>))]
        void GetTempFilterDatas(AsyncCBHandler asyncDelegate, object asyncContext);
    }



    /// <summary>
    /// 采样记录
    /// </summary>
    public class TempFilterData
    {
        /// <summary>
        /// 采集时间
        /// </summary>
        public DateTime Time { get; set; }
        /// <summary>
        /// Ad值
        /// </summary>
        public int Ad { get; set; }
        /// <summary>
        /// 滤波后的AD值
        /// </summary>
        public int FilterAd { get; set; }
        /// <summary>
        /// 复位
        /// </summary>
        public bool IsReset { get; set; }
    }

    /// <summary>
    /// 样品点 参数
    /// </summary>
    public class SampleCellParam : INotifyPropertyChanged 
    {
        /// <summary>
        /// 参数：使能
        /// </summary>
        public bool Enable { get; set; }

        /// <summary>
        /// 参数：只检查不标定
        /// </summary>
        public bool JustForCheck { get; set; }

        /// <summary>
        /// 参数：原始AD值
        /// </summary>
        public int OrgAD { get; set; }

        /// <summary>
        /// 参数：位置
        /// </summary>
        public int Position { get; set; }

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

    }


    /// <summary>
    /// 样品点
    /// </summary>
    public class SampleCell:INotifyPropertyChanged
    {

        /// <summary>
        /// 参数：使能
        /// </summary>
        public bool Enable { get; set; }

        /// <summary>
        /// 参数：只检查不标定
        /// </summary>
        public bool JustForCheck { get; set; }

        /// <summary>
        /// 参数：原始AD值
        /// </summary>
        public int OrgAD { get; set; }

        /// <summary>
        /// 参数：位置
        /// </summary>
        public int Position { get; set; }

        /// <summary>
        /// 状态：当前测量的AD值
        /// </summary>
        public int AD { get; set; }


        /// <summary>
        /// 状态：当前测量的AD值 对应的 样品值
        /// </summary>
        public double SampleValue { get; set; }

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

    }


    /// <summary>
    /// 样品正向校正特征
    /// </summary>
    public class SampleFeatureParam : INotifyPropertyChanged
    {

        /// <summary>
        /// 参数：使能
        /// </summary>
        public bool Enable { get; set; }

        /// <summary>
        /// 参数：开始位置
        /// </summary>
        public int StartPos { get; set; }

        /// <summary>
        /// 参数：结束位置
        /// </summary>
        public int EndPos { get; set; }


        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }
    /// <summary>
    /// 样品正向校正特征
    /// </summary>
    public class SampleFeature :INotifyPropertyChanged
    {

        /// <summary>
        /// 参数：使能
        /// </summary>
        public bool Enable { get; set; }


        /// <summary>
        /// 参数：开始位置
        /// </summary>
        public int StartPos { get; set; }


        /// <summary>
        /// 参数：结束位置
        /// </summary>
        public int EndPos { get; set; }


        /// <summary>
        /// 状态：相似度必须高于0.8，失败-1
        /// </summary>
        public double MaxRelevancy { get; set; } = -1;

        /// <summary>
        /// 状态：最大相似度对应的偏移
        /// </summary>
        public int MaxOffset { get; set; }


        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;


        #endregion
    }
}
