using System;
using System.ComponentModel;
using System.Drawing.Design;

namespace DH.Commons.Enums
{

    /// <summary>
    /// 标准配置
    /// </summary>
    public class Spec 
    {
        [Category("通用配置")]
        [Description("标准代码")]
        public virtual string Code { get; set; }

        [Category("通用配置")]
        [Description("启用状态,true:启用;false:禁用")]
        [DisplayName("启用状态")]
        public bool IsEnabled { get; set; }

        [Category("标准配置")]
        [Description("标准值")]
        [DisplayName("标准值")]
        public double StandardValue { get; set; }

        [Category("标准配置")]
        [Description("正公差")]
        [DisplayName("正公差")]
        public double Tolrenance_Positive { get; set; }

        [Category("标准配置")]
        [Description("负公差")]
        [DisplayName("负公差")]
        public double Tolrenance_Negative { get; set; }

        protected double? actualValue = null;
        [Browsable(false)]
       
        public virtual double? ActualValue
        {
            get
            {
                return actualValue;
            }
            set
            {
                //if (actualValue != value && value != null)
                if (value != null)
                {
                    if (value.Value >= (StandardValue - Tolrenance_Negative) && value.Value <= (StandardValue + Tolrenance_Positive))
                    {
                        MeasureResult = true;
                    }
                    else
                    {
                        MeasureResult = false;
                    }
                }

                actualValue = value;
            }
        }

        [Browsable(false)]
      
        public bool? MeasureResult { get; set; } = null;

        
        public Spec Copy()
        {
            Spec spec = new Spec();

            spec.Code = this.Code;
            spec.IsEnabled = this.IsEnabled;
            spec.StandardValue = this.StandardValue;
            spec.Tolrenance_Positive = this.Tolrenance_Positive;
            spec.Tolrenance_Negative = this.Tolrenance_Negative;

            return spec;
        }
    }

  

    public class IndexedSpec : Spec
    {
        [Category("数据源配置")]
        [Description("数据源输出索引")]
        [DisplayName("数据源输出索引")]
        public int OutputIndex { get; set; }

        public new IndexedSpec Copy()
        {
            IndexedSpec spec = new IndexedSpec();

            spec.Code = this.Code;
            spec.IsEnabled = this.IsEnabled;
            spec.StandardValue = this.StandardValue;
            spec.Tolrenance_Positive = this.Tolrenance_Positive;
            spec.Tolrenance_Negative = this.Tolrenance_Negative;

            spec.OutputIndex = this.OutputIndex;

            return spec;
        }
    }
}