using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using FObjBase.Reflect;
using System;

namespace FLY.Thick.Base.Client
{
    /// <summary>
    /// 
    /// </summary>
    public class FilmPositionDetectServiceClient : FObjBase.Reflect.Reflect_SeviceClient, IFilmPositionDetectService
    {
        protected override Type InterfaceType => typeof(IFilmPositionDetectService);
        /// <summary>
        /// AD 曲线服务 客户端代理
        /// </summary>
        /// <param name="id"></param>
        public FilmPositionDetectServiceClient(UInt32 id) : base(id) { }

        /// <summary>
        /// AD 曲线服务 客户端代理
        /// </summary>
        /// <param name="serviceId">服务id</param>
        /// <param name="connName">连接器</param>
        public FilmPositionDetectServiceClient(UInt32 serviceId, string connName) : base(serviceId, connName) { }

        #region 状态

        /// <summary>
        /// 线速度 m/min
        /// </summary>
        public double FilmVelocity { get; set; }

        /// <summary>
        /// 膜位置， m
        /// </summary>
        public double FilmPosition { get; set; }

        /// <summary>
        /// 复位标识，从同步服务器发送过来的
        /// </summary>
        public int ResetMark { get; set; }
        #endregion

        #region 参数
        /// <summary>
        /// 线速度阀值，低于阀值，速度直接变为0
        /// </summary>
        public double FilmVThreshold { get; set; }

        /// <summary>
        /// 线速度来源
        /// </summary>
        public FilmVSRC FilmVSrc { get; set; }

        /// <summary>
        /// 线速度:编码器2 mm/pulse
        /// </summary>
        public double Encoder2_mmpp { get; set; }

        /// <summary>
        /// 线速度:1圈多少mm
        /// </summary>
        public double MmOfR { get; set; }


        #endregion
        /// <summary>
        /// 设置膜位置为某值
        /// </summary>
        /// <param name="filmPos">极片位置m</param>
        public void Reset(double filmPos)
        {
            Call(nameof(Reset), new { filmPos = filmPos });
        }


        /// <summary>
        /// 让同步信号输出 1->0
        /// </summary>
        public void SyncSysTime()
        {
            Call(nameof(SyncSysTime));
        }

        /// <summary>
        /// 纵向光纤传感器检测到 0到1 变化 事件 
        /// 或
        /// sysTime同步信号触发 0到1 变化 事件 
        /// </summary>
        [Push(typeof(SysTimeFilmPosEventArgs))]
        public event EventHandler SysTimeFilmPosEvent;
        public void Trigger_SysTimeFilmPosEvent(SysTimeFilmPosEventArgs e)
        {
            SysTimeFilmPosEvent?.Invoke(this, e);
        }
        /// <summary>
        /// 设置膜位置为某值; 同步服务器调用的
        /// </summary>
        /// <param name="filmPos">极片位置m</param>
        /// <param name="sysTime">AD盒sysTime</param>
        /// <param name="resetMark">复位标识</param>
        public void Reset(double filmPos, DateTime sysTime, int resetMark)
        {
            Call(nameof(Reset), new { filmPos = filmPos, sysTime = sysTime, resetMark = resetMark });
        }
    }
}
