using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using Venus_Core.Attributes;
namespace Venus_Core
{
    /// 
    /// 设计概述:
    /// 本设计主要目的,为了满足复杂的刻蚀工艺需求(各个工艺参数之间相互关联), 和应对未来不断新增的工艺需求(新的设备、
    ///     新的工艺、新的材料等等), 同时又能对现存的Recipe保持最大的兼容
    /// 
    /// 1. 将Process 的每道工艺分解为1个至多个逻辑工艺单元, 每个逻辑工艺单元通过 Class Name 和RT的工艺算法绑定, 
    ///     同时也和 GUI Recipe Editor 的页面布局绑定。
    ///     
    /// 2. 一个逻辑单元功能调试好, 并且有在客户端使用后, 此逻辑单元想关联的 RT Process 代码和GUI 界面代码, 
    ///     不允许再修改, 只能增加新的Class 来实现新的工艺需求
    ///     
    /// 3. 通过配置文件里面定义 ProcessUnit Class Name列表, 来定义当前机台支持的工艺功能, 也就是说如果Recipe文件里面保函了
    ///     配置文件里面没有列出的工艺单元, 表明本机台不支持此Recipe, 并报警提示用户
    /// 
    public enum VenusUnits
    {
        PressureByPressureModeUnit,
        TCPUnit,
        BiasUnit,
        GasControlUnit,
        ESCHVUnit,
        ProcessKitUnit
    }
    public enum VenusCleanRecipeUnits
    {
        PressureByPressureModeUnit,
        TCPUnit,
        GasControlUnit,
        ProcessKitUnit
    }
    public enum Kepler2300Uints
    {
        PressureByPressureModeUnit,
        TCPUnit,
        BiasUnit,
        GasControlUnit,
        ProcessKitUnit
    }
    public enum Kepler2300CleanRecipeUints
    {
        PressureByPressureModeUnit,
        TCPUnit,
        GasControlUnit,
        ProcessKitUnit
    }
    public enum Kepler2200AUnits
    {
        PressureByPressureModeUnit,
        Kepler2200GasControlUnit,
        HeaterUnit,
        TCPUnit
    }
    public enum Kepler2200BUnits
    {
        PressureByPressureModeUnit,
        Kepler2200GasControlUnit,
        HeaterUnit,
        RFBoxUnit,
        TCPUnit
    }
    public enum VenusSEUnits
    {
        PressureByPressureModeUnit,
        TCPUnit,
        BiasUnit,
        VenusSEGasControlUnit,
        ESCHVUnit,
        ProcessKitUnit
    }
    public enum VenusDEUnits
    {
        PressureByPressureModeUnit,
        MagnetUnit,
        BiasUnit,
        VenusDEGasControlUnit,
        ESCHVUnit,
        ProcessKitUnit
    }
    public partial class PressureByPressureModeUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "PressureModeUnit";
        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; } = ToleranceMode.Value;
        [IsTolerance]
        [CustomName("ToleranceDelayTime(ms)")]
        public int ToleranceDelayTime { get; set; } = 3000;
        [CustomName("PressureMode")]
        public PressureUnitMode PressureUnitMode { get; set; }
        public float StartValue { get; set; }
        [IsTolerance]
        public int StartValueWarningRange { get; set; } = 5;
        [IsTolerance]
        public int StartValueAlarmRange { get; set; } = 10;
        public int ValvePositionPreset { get; set; }
        [IsCanConfigIgnore]
        public bool EnableRamp { get; set; }
        public int HoldTime { get; set; }
        public float TargetValue { get; set; }
        //public event PropertyChangedEventHandler PropertyChanged;
        //public void InvokePropertyChanged(string propertyName)
        //{
        //    if (PropertyChanged != null)
        //    {
        //        PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        //    }
        //}
    }
    public class HeaterUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "HeaterUnit";
        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; }
        [IsTolerance]
        [CustomName("ToleranceDelayTime(ms)")]
        public int ToleranceDelayTime { get; set; }
        [CustomName("Heater Temperature(℃)")]
        public int HeaterTemp { get; set; }
        [IsTolerance]
        public int HeaterTempWarningRange { get; set; }
        [IsTolerance]
        public int HeaterTempAlarmRange { get; set; }
        [CustomName("Heater Ratio")]
        public int HeaterRatio { get; set; }
        public Suspect SuspectPosition { get; set; }
        public int PositionOffset { get; set; }
    }
    public class TCPUnit : ProcessUnitBase
    {
        private string m_UnitName = "TCPUnit";
        public string UnitName
        {
            get { return m_UnitName; }
            set { m_UnitName = value; }
        }
        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; } = ToleranceMode.Value;
        [IsTolerance]
        [CustomName("ToleranceDelayTime(ms)")]
        public int ToleranceDelayTime { get; set; } = 3000;
        [CustomName("RF Power(W)")]
        public int RFPower { get; set; }
        [IsTolerance]
        public int RFPowerWarningRange { get; set; } = 5;
        [IsTolerance]
        public int RFPowerAlarmRange { get; set; } = 10;
        [CustomName("C1(%)")]
        public float C1 { get; set; }
        [CustomName("C2(%)")]
        public float C2 { get; set; }
        [IsOnlyRead]
        [CustomName("AutoC1(%)")]
        public float AutoC1 { get; set; }
        [IsOnlyRead]
        [CustomName("AutoC2(%)")]
        public float AutoC2 { get; set; }
        [CustomName("RF Max ReflectedPower(W)")]
        public int MaxReflectedPower { get; set; }
        [JsonConverter(typeof(StringEnumConverter))]
        public MatchWorkMode MatchWorkMode { get; set; }
        private bool m_EnableRamp;
        [IsCanConfigIgnore]
        public bool EnableRamp
        {
            get { return m_EnableRamp; }
            set { m_EnableRamp = value; }
        }
        //public int StartPower { get; set; }
        public int TargetRFPower { get; set; }
    }
    public class BiasUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "BiasUnit";
        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; } = ToleranceMode.Value;
        [IsTolerance]
        [CustomName("ToleranceDelayTime(ms)")]
        public int ToleranceDelayTime { get; set; } = 3000;
        //public int RFPower { get; set; }
        [IsTolerance]
        public int RFPowerWarningRange { get; set; } = 5;
        [IsTolerance]
        public int RFPowerAlarmRange { get; set; } = 10;
        [CustomName("BiasRF Power(W)")]
        public int BiasRFPower { get; set; }
        [CustomName("BiasC1(%)")]
        public float BiasC1 { get; set; }
        [CustomName("BiasC2(%)")]
        public float BiasC2 { get; set; }
        [IsOnlyRead]
        [CustomName("AutoBiasC1(%)")]
        public float AutoBiasC1 { get; set; }
        [CustomName("AutoBiasC2(%)")]
        [IsOnlyRead]
        public float AutoBiasC2 { get; set; }
        [CustomName("BiasRF Max ReflectedPower(W)")]
        public int BiasMaxReflectedPower { get; set; }
        [JsonConverter(typeof(StringEnumConverter))]
        public MatchWorkMode BiasMatchWorkMode { get; set; }
        [JsonConverter(typeof(StringEnumConverter))]
        public GeneratorMode BiasGeneratorMode { get; set; }
        public int PulseRateFreq { get; set; }
        public int PulseDutyCycle { get; set; }
        [IsCanConfigIgnore]
        public bool EnableRamp { get; set; }
        [JsonConverter(typeof(StringEnumConverter))]
        public TargetMode TargetMode { get; set; }
        //public int StartBiasRFPower { get; set; } 
        public int TargetBiasRFPower { get; set; }
    }
    public class RFBoxUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "RFBoxUnit";
        [CustomName("RFBox C1(%)")]
        public float C1 { get; set; }
    }
    public class GasControlUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "GasControlUnit";
        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; }
        [IsTolerance]
        [CustomName("ToleranceDelayTime(ms)")]
        public int ToleranceDelayTime { get; set; }
        public int Gas1 { get; set; }
        [IsTolerance]
        public int Gas1WarningRange { get; set; }
        [IsTolerance]
        public int Gas1AlarmRange { get; set; }
        public int Gas2 { get; set; }
        [IsTolerance]
        public int Gas2WarningRange { get; set; }
        [IsTolerance]
        public int Gas2AlarmRange { get; set; }
        public int Gas3 { get; set; }
        [IsTolerance]
        public int Gas3WarningRange { get; set; }
        [IsTolerance]
        public int Gas3AlarmRange { get; set; }
        public int Gas4 { get; set; }
        [IsTolerance]
        public int Gas4WarningRange { get; set; }
        [IsTolerance]
        public int Gas4AlarmRange { get; set; }
        public int Gas5 { get; set; }
        [IsTolerance]
        public int Gas5WarningRange { get; set; }
        [IsTolerance]
        public int Gas5AlarmRange { get; set; }
        public int Gas6 { get; set; }
        [IsTolerance]
        public int Gas6WarningRange { get; set; }
        [IsTolerance]
        public int Gas6AlarmRange { get; set; }
        public int Gas7 { get; set; }
        [IsTolerance]
        public int Gas7WarningRange { get; set; }
        [IsTolerance]
        public int Gas7AlarmRange { get; set; }
        public int Gas8 { get; set; }
        [IsTolerance]
        public int Gas8WarningRange { get; set; }
        [IsTolerance]
        public int Gas8AlarmRange { get; set; }
        [IsCanConfigIgnore]
        public bool EnableRamp { get; set; }
        public int Gas1Target { get; set; }
        public int Gas2Target { get; set; }
        public int Gas3Target { get; set; }
        public int Gas4Target { get; set; }
        public int Gas5Target { get; set; }
        public int Gas6Target { get; set; }
        public int Gas7Target { get; set; }
        public int Gas8Target { get; set; }
        public int FlowRatie { get; set; }
    }
    public class Kepler2200GasControlUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "GasUnit";
        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; }
        [IsTolerance]
        [CustomName("ToleranceDelayTime(ms)")]
        public int ToleranceDelayTime { get; set; }
        public float Gas1 { get; set; }
        [IsTolerance]
        public float Gas1WarningRange { get; set; }
        [IsTolerance]
        public float Gas1AlarmRange { get; set; }
        public int Gas2 { get; set; }
        [IsTolerance]
        public int Gas2WarningRange { get; set; }
        [IsTolerance]
        public int Gas2AlarmRange { get; set; }
        public int Gas3 { get; set; }
        [IsTolerance]
        public int Gas3WarningRange { get; set; }
        [IsTolerance]
        public int Gas3AlarmRange { get; set; }
        public int Gas4 { get; set; }
        [IsTolerance]
        public int Gas4WarningRange { get; set; }
        [IsTolerance]
        public int Gas4AlarmRange { get; set; }
        public int Gas5 { get; set; }
        [IsTolerance]
        public int Gas5WarningRange { get; set; }
        [IsTolerance]
        public int Gas5AlarmRange { get; set; }
        public int Gas6 { get; set; }
        [IsTolerance]
        public int Gas6WarningRange { get; set; }
        [IsTolerance]
        public int Gas6AlarmRange { get; set; }
        public int Gas7 { get; set; }
        [IsTolerance]
        public int Gas7WarningRange { get; set; }
        [IsTolerance]
        public int Gas7AlarmRange { get; set; }
        public int Gas8 { get; set; }
        [IsTolerance]
        public int Gas8WarningRange { get; set; }
        [IsTolerance]
        public int Gas8AlarmRange { get; set; }
    }
    public class MagnetUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "Magnet";
        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; } = ToleranceMode.Value;
        [IsTolerance]
        [CustomName("ToleranceDelayTime(ms)")]
        public int ToleranceDelayTime { get; set; } = 3000;
        public float MagnetIntensity { get; set; }
        [IsTolerance]
        public int IntensityWarningRange { get; set; } = 5;
        public float FieldRatio { get; set; }
        public int MagnetWaveform { get; set; }
    }
    public class VenusSEGasControlUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "SEGasControlUnit";
        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; } = ToleranceMode.Value;
        [IsTolerance]
        [CustomName("ToleranceDelayTime(ms)")]
        public int ToleranceDelayTime { get; set; } = 3000;
        public float Gas1 { get; set; }
        [IsTolerance]
        public float Gas1WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas1AlarmRange { get; set; } = 10;
        public float Gas2 { get; set; }
        [IsTolerance]
        public float Gas2WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas2AlarmRange { get; set; } = 10;
        public float Gas3 { get; set; }
        [IsTolerance]
        public float Gas3WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas3AlarmRange { get; set; } = 10;
        public float Gas4 { get; set; }
        [IsTolerance]
        public float Gas4WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas4AlarmRange { get; set; } = 10;
        public float Gas5 { get; set; }
        [IsTolerance]
        public float Gas5WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas5AlarmRange { get; set; } = 10;
        public float Gas6 { get; set; }
        [IsTolerance]
        public float Gas6WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas6AlarmRange { get; set; } = 10;
        public float Gas7 { get; set; }
        [IsTolerance]
        public float Gas7WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas7AlarmRange { get; set; } = 10;
        public float Gas8 { get; set; }
        [IsTolerance]
        public float Gas8WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas8AlarmRange { get; set; } = 10;
        public float Gas9 { get; set; }
        [IsTolerance]
        public float Gas9WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas9AlarmRange { get; set; } = 10;
        public float Gas10 { get; set; }
        [IsTolerance]
        public float Gas10WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas10AlarmRange { get; set; } = 10;
        public float Gas11 { get; set; }
        [IsTolerance]
        public float Gas11WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas11AlarmRange { get; set; } = 10;
        public float Gas12 { get; set; }
        [IsTolerance]
        public float Gas12WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas12AlarmRange { get; set; } = 10;
    }
    public class VenusDEGasControlUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "DEGasControlUnit";
        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; } = ToleranceMode.Value;
        [IsTolerance]
        [CustomName("ToleranceDelayTime(ms)")]
        public int ToleranceDelayTime { get; set; } = 3000;
        public float Gas1 { get; set; }
        [IsTolerance]
        public float Gas1WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas1AlarmRange { get; set; } = 10;
        public float Gas2 { get; set; }
        [IsTolerance]
        public float Gas2WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas2AlarmRange { get; set; } = 10;
        public float Gas3 { get; set; }
        [IsTolerance]
        public float Gas3WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas3AlarmRange { get; set; } = 10;
        public float Gas4 { get; set; }
        [IsTolerance]
        public float Gas4WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas4AlarmRange { get; set; } = 10;
        public float Gas5 { get; set; }
        [IsTolerance]
        public float Gas5WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas5AlarmRange { get; set; } = 10;
        public float Gas6 { get; set; }
        [IsTolerance]
        public float Gas6WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas6AlarmRange { get; set; } = 10;
        public float Gas7 { get; set; }
        [IsTolerance]
        public float Gas7WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas7AlarmRange { get; set; } = 10;
        public float Gas8 { get; set; }
        [IsTolerance]
        public float Gas8WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas8AlarmRange { get; set; } = 10;
        public float Gas9 { get; set; }
        [IsTolerance]
        public float Gas9WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas9AlarmRange { get; set; } = 10;
        public float Gas10 { get; set; }
        [IsTolerance]
        public float Gas10WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas10AlarmRange { get; set; } = 10;
        public float Gas11 { get; set; }
        [IsTolerance]
        public float Gas11WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas11AlarmRange { get; set; } = 10;
        public float Gas12 { get; set; }
        [IsTolerance]
        public float Gas12WarningRange { get; set; } = 5;
        [IsTolerance]
        public float Gas12AlarmRange { get; set; } = 10;
    }
    public class ESCHVUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "ESCHVUnit";
        [CustomName("BacksideHelium(Torr)")]
        public int BacksideHelium { get; set; }
        [CustomName("HeCheckDelayTime(ms)")]
        public int CheckDelay { get; set; }
        public float MinHeFlow { get; set; }
        public float MaxHeFlow { get; set; }
        public int ESCClampValtage { get; set; }
    }
    public class ProcessKitUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "ProcessKitUnit";
        private MovementPosition m_LiftPinPostion;
        [JsonConverter(typeof(StringEnumConverter))]
        public MovementPosition LiftPinPostion
        {
            get { return m_LiftPinPostion; }
            set { m_LiftPinPostion = value; }
        }
        [JsonConverter(typeof(StringEnumConverter))]
        public MovementPosition WeprBasrPinPosition { get; set; }
    }
    //public override Dictionary GetFDCItems()
    //{
    //    Dictionary FdcItems = new Dictionary();          
    //    FdcItems.Add("MfcGas1.FeedBack", Gas1);
    //    FdcItems.Add("MfcGas2.FeedBack", Gas2);
    //    FdcItems.Add("MfcGas3.FeedBack", Gas3);
    //    FdcItems.Add("MfcGas4.FeedBack", Gas4);
    //    FdcItems.Add("MfcGas5.FeedBack", Gas5);
    //    FdcItems.Add("MfcGas6.FeedBack", Gas6);
    //    return FdcItems;
    //}
    public class HeliosBiasRFKitUnit
    { 
    
    }
}