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;

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


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

        /// <summary>
        /// 参数：样品点范围
        /// </summary>
        int Range { get; set; }

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

        /// <summary>
        /// 使用%方式检查异常
        /// </summary>
        bool IsCheckByPercent { get; set; }
        /// <summary>
        /// 异常%
        /// </summary>
        double ErrPercent { get; set; }
        /// <summary>
        /// 异常值
        /// </summary>
        int ErrValue { get; set; }
        /// <summary>
        /// 参数：样品点参数
        /// </summary>
        SampleCell[] Samples { get; }
        /// <summary>
        /// 参数：特征查找范围
        /// </summary>
        int Search { get; set; }
        /// <summary>
        /// 参数：特征参数
        /// </summary>
        SampleFeature[] Features { get; }

        /// <summary>
        /// 状态：从flyad7 得到的。 用于绘制图
        /// </summary>
        int PosOfGrid { get; set;}


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

        /// <summary>
        ///  返回 List(List(TempFilterData))
        /// </summary>
        /// <param name="asyncCB"></param>
        /// <param name="asyncContext"></param>
        void GetTempFilterDatas(AsyncCBHandler asyncCB, 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>
    [JsonObject(MemberSerialization.OptIn)]
    public class SampleCell:INotifyPropertyChanged
    {

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

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

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

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

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


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


        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

    }
    
    
    /// <summary>
    /// 样品正向校正特征
    /// </summary>
    [JsonObject(MemberSerialization.OptIn)]
    public class SampleFeature :INotifyPropertyChanged
    {

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


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


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


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

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

        /// <summary>
        /// 状态：扫描数据，从扫描数据提取的相似的一段
        /// 它的单位是 grid, 需要 posOfGrid, 转换为 pos
        /// 开始位置是 StartPos - Search
        /// </summary>
        [DoNotCheckEquality]
        public int[] ScanData { get; set; }

        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;


        #endregion
    }
}
