using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.ComponentModel;
using CyberX8_Core.Attributes;

namespace CyberX8_Core
{
    /// <summary>
    /// 设计概述:
    /// 本设计主要目的,为了满足复杂的刻蚀工艺需求(各个工艺参数之间相互关联), 和应对未来不断新增的工艺需求(新的设备、
    ///     新的工艺、新的材料等等), 同时又能对现存的Recipe保持最大的兼容
    /// 
    /// 1. 将Process 的每道工艺分解为1个至多个逻辑工艺单元, 每个逻辑工艺单元通过 Class Name 和RT的工艺算法绑定, 
    ///     同时也和 GUI Recipe Editor 的页面布局绑定。
    ///     
    /// 2. 一个逻辑单元功能调试好, 并且有在客户端使用后, 此逻辑单元想关联的 RT Process 代码和GUI 界面代码, 
    ///     不允许再修改, 只能增加新的Class 来实现新的工艺需求
    ///     
    /// 3. 通过配置文件里面定义 ProcessUnit Class Name列表, 来定义当前机台支持的工艺功能, 也就是说如果Recipe文件里面保函了
    ///     配置文件里面没有列出的工艺单元, 表明本机台不支持此Recipe, 并报警提示用户
    /// </summary>

    
    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,
        TCPUnit
    }

    public enum VenusSEUnits
    {
        PressureByPressureModeUnit,
        TCPUnit,
        BiasUnit,
        VenusSEGasControlUnit,
        ESCHVUnit,
        ProcessKitUnit
    }

    public enum VenusDEUnits
    {

    }

    public partial class PressureByPressureModeUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "PressureModeUnit";

        public PressureUnitMode PressureUnitMode { get; set; }
        public int StartValue { get; set; }

        public int ValvePositionPreset { get; set; }
        [IsCanConfigIgnore]
        public bool EnableRamp { get; set; }
        public int HoldTime { get; set; }
        public int 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";
        public int HeaterTemp { get; set; }
        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; }
        [IsTolerance]
        public int ToleranceDelayTime_ms { get; set; }
        public int RFPower { get; set; }
        [IsTolerance]
        public int RFPowerWarningRange { get; set; }
        [IsTolerance]
        public int RFPowerAlarmRange { get; set; }
        public int C1 { get; set; }
        public int C2 { get; set; }
        [IsOnlyRead]
        public int AutoC1 { get; set; }
        [IsOnlyRead]
        public int AutoC2 { get; set; }
        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; }
        [IsTolerance]
        public int ToleranceDelayTime_ms { get; set; }
        public int RFPower { get; set; }
        [IsTolerance]
        public int RFPowerWarningRange { get; set; }
        [IsTolerance]
        public int RFPowerAlarmRange { get; set; }
        public int BiasRFPower { get; set; }
        public int BiasC1{ get; set; }
        public int BiasC2 { get; set; }
        [IsOnlyRead]
        public int AutoBiasC1 { get; set; }
        [IsOnlyRead]
        public int AutoBiasC2 { get; set; }
        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 GasControlUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "GasControlUnit";

        [IsTolerance]
        public ToleranceMode ToleranceMode { get; set; }
        [IsTolerance]
        public int ToleranceDelayTime_ms { 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]
        public int ToleranceDelayTime_ms { 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 class VenusSEGasControlUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "SEGasControlUnit";
        public int Gas1 { get; set;}
        public int Gas2 { get; set;}
        public int Gas3 { get; set;}
        public int Gas4 { get; set;}
        public int Gas5 { get; set;}
        public int Gas6 { get; set;}
        public int Gas7 { get; set;}
        public int Gas8 { get; set;}
        public int Gas9 { get; set;}
        public int Gas10 { get; set;}
        public int Gas11 { get; set;}
        public int Gas12 { get; set;}
    }

    public class ESCHVUnit : ProcessUnitBase
    {
        public string UnitName { get; set; } = "ESCHVUnit";
        public int BacksideHelum { get; set; } 
        public int MinHeFlow { get; set; } 
        public int MaxHeFlow { get; set; } 
        public int ESCClampValtage { get; set; }
        public int Temperature { 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; }
    }
}