using FLY.Thick.FilmCasting.Server.Model;
using FObjBase;
using FObjBase.Reflect;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLY.Thick.FilmCasting.IService
{
    /// <summary>
    /// 基于DB 的 bulkdata
    /// </summary>
    public interface IBulkDbService : INotifyPropertyChanged
    {
        /// <summary>
        /// 最后一条扫描数据Id
        /// </summary>
        long LastScanDataId { get; }
        /// <summary>
        /// 最后一条产品Id
        /// </summary>
        long LastProfileId { get; }
        /// <summary>
        /// 最后一条产品被修改的时间
        /// </summary>
        DateTime LastTimestamp { get; }



        /// <summary>
        /// 开始产生数据时间
        /// </summary>
        DateTime StartTime { get; }

        /// <summary>
        /// 最后产生数据时间
        /// </summary>
        DateTime EndTime { get; }

        /// <summary>
        /// 当前生产，已经结束，已经下辊了
        /// </summary>
        bool IsFinished { get; }

        /// <summary>
        /// 临时数据改变
        /// </summary>
        [Push(typeof(BulkDbTempFrameChangedEventArgs))]
        event EventHandler TempFrameChanged;

        /// <summary>
        /// 获取临时数据
        /// </summary>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(BulkDbTempFrameChangedEventArgs))]
        void GetTempFrame(
            AsyncCBHandler asyncDelegate, object asyncContext);

        #region 统计

        /// <summary>
        /// 获取历史profile
        /// </summary>
        /// <param name="request"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(Pack_GetProfileReponse))]
        void GetProfile(
            Pack_GetProfileRequest request,
            AsyncCBHandler asyncDelegate, object asyncContext);

        /// <summary>
        /// 获取一幅数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(Pack_GetFrameReponse))]
        void GetFrame(
            Pack_GetFrameRequest request,
            AsyncCBHandler asyncDelegate, object asyncContext);

        /// <summary>
        /// 获取一幅数据 且 对应的Profile
        /// </summary>
        /// <param name="request"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(Pack_GetFrame2Reponse))]
        void GetFrame2(
            Pack_GetFrameRequest request,
            AsyncCBHandler asyncDelegate, object asyncContext);


        /// <summary>
        /// 获取近期的大量数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(Pack_GetRecentFramesReponse))]
        void GetRecentFrames(
            Pack_GetRecentFramesRequest request,
            AsyncCBHandler asyncDelegate, object asyncContext);


        /// <summary>
        /// 获取纵向趋势图
        /// </summary>
        /// <param name="request"></param>
        /// <param name="asyncDelegate"></param>
        /// <param name="asyncContext"></param>
        [Call(typeof(Pack_GetTrendReponse))]
        void GetTrend(
            Pack_GetTrendRequest request,
            AsyncCBHandler asyncDelegate, object asyncContext);



        #endregion


        /// <summary>
        /// 完成,下辊。。。
        /// </summary>
        void Finish();
    }
    /// <summary>
    /// 
    /// </summary>
    public class Pack_GetRecentFramesRequest
    {
        /// <summary>
        /// 最后1幅数据ID, 当≤0, 从数据库最后获取
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 获取数据集数
        /// </summary>
        public int Count { get; set; }

        /// <summary>
        /// 混合的数据 时间范围限制
        /// 与最新的图比较， 时间差不能超过 TimeRange
        /// 大于 TimeSpan.Zero 起作用
        /// </summary>
        public DateTime FromTime { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class Pack_GetRecentFramesReponse 
    {
        /// <summary>
        /// 
        /// </summary>
        public Pack_GetRecentFramesRequest Request { get; set; }
        /// <summary>
        /// scanDatas[0] 是最新的数据
        /// </summary>
        public List<Lc_ScanData> scanDatas { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class Pack_GetFrameRequest
    {
        /// <summary>
        /// 最后1幅数据ID, 当≤0, 从数据库最后获取
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 混合数
        /// </summary>
        public int Mix { get; set; }

    }
    /// <summary>
    /// 
    /// </summary>
    public class Pack_GetProfileRequest
    {
        /// <summary>
        /// profile表的ID
        /// </summary>
        public long Id { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class Pack_GetProfileReponse
    {
        public Pack_GetProfileRequest Request { get; set; }
        public Db_Profile profile { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class Pack_GetFrameReponse
    {
        public Pack_GetFrameRequest Request { get; set; }
        public Lc_ScanData scanData { get; set; }
        /// <summary>
        /// 混合数
        /// </summary>
        public int mix { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class Pack_GetFrame2Reponse
    {
        public Pack_GetFrameRequest Request { get; set; }
        public Lc_ScanData scanData { get; set; }
        public Db_Profile profile { get; set; }
        /// <summary>
        /// 混合数
        /// </summary>
        public int mix { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class Pack_GetTrendRequest
    {
        /// <summary>
        /// 最后1幅数据ID, 当≤0, 从数据库最后获取
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 长度
        /// </summary>
        public int Count { get; set; }

        /// <summary>
        /// 间隔, 只获取 Id % Interval == 0 的数据
        /// </summary>
        public int Interval { get; set; }

        /// <summary>
        /// 混合数，经过间隔后的数据再混合
        /// </summary>
        public int Mix { get; set; }

        /// <summary>
        /// 按时间查找数据
        /// </summary>
        public bool IsSearchByTime { get; set; }

        /// <summary>
        /// 按时间查找数据, 获取的数据对应的时间都比Time小
        /// </summary>
        public DateTime Time { get; set; }


    }
    /// <summary>
    /// 
    /// </summary>
    public class Pack_GetTrendReponse
    {
        /// <summary>
        /// 
        /// </summary>
        public Pack_GetTrendRequest Request { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public List<TrendValue> Values { get; set; }
        /// <summary>
        /// 最后1幅数据ID, ≤0, 从数据库最后获取
        /// </summary>
        public long ScanDataId { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class TrendValue
    {
        /// <summary>
        /// 产品 ID
        /// </summary>
        public long ProfileID { get; set; }
        /// <summary>
        /// 扫描 ID
        /// </summary>
        public long ScanDataID { get; set; }
        /// <summary>
        /// σ
        /// </summary>
        public double Sigma { get; set; }
        /// <summary>
        /// 平均值
        /// </summary>
        public double Value { get; set; }
        /// <summary>
        /// 时间
        /// </summary>
        public DateTime Time { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class BulkDbTempFrameChangedEventArgs : EventArgs
    {
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime Time { get; set; }
        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime EndTime { get; set; }
        /// <summary>
        /// 开始位置
        /// </summary>
        public int StartIndex { get; set; }
        /// <summary>
        /// 数据
        /// </summary>
        public double[] D { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class ScanDataIdChangedEventArgs : EventArgs
    {
        /// <summary>
        /// 最后1幅数据ID, 当≤0, 从数据库最后获取
        /// </summary>
        public long LastScanDataId;
    }
}
