using AutoMapper;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using FLY.Thick.Base.OBJ_INTERFACE;
using FObjBase;
using FObjBase.Reflect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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; protected set; }
        /// <summary>
        /// 膜位置， m
        /// </summary>
        public double FilmPosition { get; protected set; }
        /// <summary>
        /// 纵向位置偏移 m
        /// </summary>
        public double FilmOffset { get; protected set; }
        /// <summary>
        /// 工作中
        /// </summary>
        public bool IsRunning { get; protected set; }

        /// <summary>
        /// 当前正在使用的 与机头测厚仪偏移，单位m
        /// </summary>
        public double VDistanceWithHeaderInUsed { get; protected set; }

        /// <summary>
        /// 当前正在使用的 激光探头与 X光的偏移，单位m
        /// </summary>
        public double VSensorOffsetInUsed { get; protected 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; }

        /// <summary>
        /// 本测厚仪探头与机头测厚仪探头距离单位m
        /// </summary>
        public double VDistanceWithHeader { get; set; }

        /// <summary>
        /// 纵向光纤传感器与本测厚仪探头距离 单位m;
        /// 修改此值，会改变纵向偏移
        /// </summary>
        public double VSensorOffset { get; set; }

        #endregion

        /// <summary>
        /// 主轴激光传感器检测到 1->0 变化 事件
        /// </summary>
        [Push(typeof(FilmPosAt01EventArgs), "Trigger_FilmPosAt01Event")]
        public event EventHandler FilmPosAt01Event;

        public void Trigger_FilmPosAt01Event(FilmPosAt01EventArgs e) {
            FilmPosAt01Event?.Invoke(this, e);
        }
        /// <summary>
        /// 设置膜位置为某值
        /// </summary>
        /// <param name="filmPosition">极片位置m</param>
        public void ResetCore(double filmPosition) 
        {
            Call("ResetCore", new { filmPosition });
        }
        /// <summary>
        /// 改变逻辑偏移量，从而设置膜位置为某值
        /// </summary>
        /// <param name="filmPosition"></param>
        public void ResetOffset(double filmPosition)
        {
            Call("ResetOffset", new { filmPosition });
        }

        /// <summary>
        /// 设置逻辑偏移量
        /// </summary>
        /// <param name="filmOffset"></param>
        public void SetOffset(double filmOffset)
        {
            Call("SetOffset", new { filmOffset });
        }
        /// <summary>
        /// 把膜位置设置为 -VDistanceWithHeader
        /// </summary>
        public void Reset()
        {
            Call("Reset");
        }



        /// <summary>
        /// 服务器 从 机头得到的 0->1 事件，给机尾
        /// </summary>
        /// <param name="filmPos">极片位置m</param>
        public void SetFilmPosAt01(double filmPos)
        {
            Call("SetFilmPosAt01", new { filmPos });
        }

        /// <summary>
        /// 停止测量
        /// </summary>
        public void Stop() 
        {
            Call("Stop");
        }

        /// <summary>
        /// 启动测量
        /// </summary>
        public void Start() 
        {
            Call("Start");
        }

        public void Apply()
        {
            Call("Apply");

        }
    }
}
