using FLY.FeedbackRenZiJia.Common;
using FLY.FeedbackRenZiJia.IService;
using FLY.FeedbackRenZiJia.OBJ_INTERFACE;
using FObjBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace FLY.FeedbackRenZiJia.Client
{
    public class HeatBufServiceClient : FObjBase.Reflect.Reflect_SeviceClient, IHeatBufService
    {
        protected override Type InterfaceType => typeof(IHeatBufService);
        #region 属性,对外接口
        #region 参数
        /// <summary>
        /// 加热生效曲线,允许为空,则不生效
        /// </summary>
        public int[] HeatEffectCurve { get; set; } 


        /// <summary>
        /// 厚度稳定范围 %, 偏差在范围内,都是稳定的 
        /// </summary>
        public int StableRange { get; set; } = 2;




        /// <summary>
        /// 对位模式, 加热与厚度相关性阀值, 相关性 >=0.7
        /// </summary>
        public double ThresholdR { get; set; } = 0.7;


        /// <summary>
        /// 对位模式 厚度%差 的极差 >= +4%-4%=8%, 单位%
        /// </summary>
        public int ThresholdMaxMin { get; set; } = 8;


        /// <summary>
        /// %
        /// 最大sigma, 只有当前的sigma  在 最大sigma 与 最小 sigma 内,才能控制
        /// </summary>
        public int ThresholdSigmaMax { get; set; } = 20;


        /// <summary>
        /// %
        /// 最小sigma, 只有当前的sigma  在 最大sigma 与 最小 sigma 内,才能控制
        /// </summary>
        public double ThresholdSigmaMin { get; set; } = 2;
        
        #endregion

        #region 状态


        /// <summary>
        /// 总延时 =Delay+mRenZiJiaService.FilmLength/mRenZiJiaService.Velocity
        /// </summary>
        public TimeSpan Delay { get; set; } = TimeSpan.FromSeconds(100);

        #region 对位

        /// <summary>
        /// 对位查找范围 默认 ±120°, 最大值 180°,最小值 50°
        /// </summary>
        public int SearchAngleRange { get; set; } = 120;
        /// <summary>
        /// 计算的最佳复位区号
        /// </summary>
        public int BestOrgBoltNo { get; set; } = -1;

        /// <summary>
        /// 计算的最佳复位区号 对应的 加热/厚度 
        /// </summary>
        public double BestKp { get; set; } = -1;


        /// <summary>
        /// 计算的最佳复位区号 对应的 加热与厚度相关性
        /// </summary>
        public double MaxR { get; set; } = -1;


        /// <summary>
        /// 计算的最佳复位区号 对应的 厚度%变化极差 单位%
        /// </summary>
        public int MaxMin { get; set; } = -1;

        /// <summary>
        /// MaxR 对应的 数据幅 Id0
        /// </summary>
        public long MaxR_Id0 { get; set; }

        /// <summary>
        /// MaxR 对应的 数据幅 Id1
        /// </summary>
        public long MaxR_Id1 { get; set; }

        /// <summary>
        /// MaxR 对应的 数据幅 时间
        /// </summary>
        public DateTime MaxR_Time { get; set; }
        #endregion

        #region 稳定性

        /// <summary>
        /// 当前检测出来的厚度数据 稳定状态
        /// </summary>
        public STABILITY Stability { get; set; } = STABILITY.IDLE;



        /// <summary>
        /// 当前检测出来的厚度数据 的稳定性 
        /// </summary>
        public double CurrR { get; set; } = -1;


        /// <summary>
        /// 当前检测出来的厚度数据 2Sigma
        /// </summary>
        public double Curr2Sigma { get; set; } = -1;


        /// <summary>
        /// 当前检测出来的厚度数据,时间
        /// </summary>
        public DateTime CurrTime { get; set; } = DateTime.MinValue;



        #endregion

        #region 每个分区状态

        public bool[] BoltIsStable { get; set; }

        #endregion
        #endregion


        #endregion

        public HeatBufServiceClient(UInt32 serviceId) : base(serviceId) { }
        public HeatBufServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }


        public void Apply()
        {
            Call(nameof(Apply));
        }




    }
}