using System;
using System.ComponentModel.DataAnnotations;

namespace Aitex.Core.RT.Device.PmDevices
{
    public enum FlowMode
            {
                Purge,
                Vent,
                Run,
                Close,
            }
    
            public enum ArH2Switch
            {
                Ar,
                H2,
            }
    
            /// <summary>
            /// 2704每通道工作模式
            /// </summary>
            public enum TCModes
            {
                /// <summary>
                /// 自动模式
                /// </summary>
                Auto,
    
                /// <summary>
                /// 手动模式
                /// </summary>
                Manual
            }
    
            /// <summary>
            /// 温度控制策略。
            /// </summary>
            public enum HeatStrategy
            {
                /// <summary>
                /// 功率控制
                /// </summary>
                [Display(Name = "Power")]
                Power,
    
                /// <summary>
                /// 对于PSU：L2自动控温；L1、L3功率控制，输出功率按比例跟随L2
                /// 对于SCR：L3自动控温；L1、L2功率控制，输出功率按比例跟随L2
                /// </summary>
                [Display(Name = "Follow")]
                PyroFollow,
                    
                /// <summary>
                /// L2、L3自动控温；L1功率控制，输出功率按比例跟随L1
                /// </summary>
                [Display(Name = "Auto")]
                PyroAuto
            }
    
            /// <summary>
            /// 加热控制单元。
            /// <para>
            /// TC1即PSU；TC2即SCR
            /// </para>
            /// </summary>
            public enum TCUnits
            {
                PSU,
                SCR,
                TC1, // PSU
                TC2  // SCR
            }

    
    public class DicMode
    {
        /// <summary>
        /// 检查指定名称的设备是否为PSU。
        /// </summary>
        /// <param name="name">设备名称</param>
        /// <returns></returns>
        public static bool IsPSU(string name)
        {
            return name == TCUnits.PSU.ToString() || name == TCUnits.TC1.ToString();
        }

        /// <summary>
        /// 检查类型为<see cref="TCUnits"/>的设备是否为PSU。
        /// </summary>
        /// <param name="tc">设备类型</param>
        /// <returns></returns>
        public static bool IsPSU(TCUnits tc)
        {
            return tc is TCUnits.PSU or TCUnits.TC1;
        }

        /// <summary>
        /// 检查指定名称的设备是否为SCR。
        /// </summary>
        /// <param name="name">设备名称</param>
        /// <returns></returns>
        public static bool IsSCR(string name)
        {
            return name == TCUnits.SCR.ToString() || name == TCUnits.TC2.ToString();
        }

        /// <summary>
        /// 检查类型为<see cref="TCUnits"/>的设备是否为SCR。
        /// </summary>
        /// <param name="tc">设备类型</param>
        /// <returns></returns>
        public static bool IsSCR(TCUnits tc)
        {
            return tc is TCUnits.SCR or TCUnits.TC2;
        }

        /// <summary>
        /// 将指定的数字转换为<see cref="TCModes"/>枚举。
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public static TCModes ConvertToTcModes(int mode)
        {
            if (Enum.IsDefined(typeof(TCModes), mode))
                return (TCModes)mode;

            return TCModes.Manual;
        }

        /// <summary>
        /// 将指定的数字转换为<see cref="HeatStrategy"/>枚举。
        /// </summary>
        /// <param name="mode"></param>
        /// <returns></returns>
        public static HeatStrategy ConvertToHeatStrategy(int mode)
        {
            var strategy = HeatStrategy.Power;
            if (Enum.IsDefined(typeof(HeatStrategy), mode))
                strategy = (HeatStrategy)mode;

            return strategy;
        }
    }
}
