package com.hdkj.lt.bf.constants;

import java.util.Objects;

/**
 * @author luorui
 * @date 2025/9/15 13:13
 */
public class SwitchSettingConstants {

    /**
     * 是否联络开关 1-是，0-否
     **/
    public enum YesOrNoEnum {
        /**
         * 是
         */
        YES("1", "是"),

        /**
         * 否
         */
        NO("0", "否");

        final String code;

        final String name;

        YesOrNoEnum(String code, String name) {
            this.code = code;
            this.name = name;
        }

        public String getCode() {
            return this.code;
        }

        public String getName() {
            return this.name;
        }

        public static YesOrNoEnum getByCode(String code) {
            YesOrNoEnum[] values = values();
            for (YesOrNoEnum item : values) {
                if (Objects.equals(item.getCode(), code)) {
                    return item;
                }
            }
            return null;
        }

        public static String getNameByCode(String code) {
            YesOrNoEnum[] values = values();
            for (YesOrNoEnum item : values) {
                if (Objects.equals(item.getCode(), code)) {
                    return item.name;
                }
            }
            return code;
        }
    }

    /**
     * 设置类型1-告警，2-跳闸
     */
    public enum SwitchActionEnum {
        /**
         * 告警
         */
        ALARM(1, "告警"),

        /**
         * 跳闸
         */
        TRIP(2, "跳闸");

        final Integer code;

        final String name;

        SwitchActionEnum(Integer code, String name) {
            this.code = code;
            this.name = name;
        }

        public Integer getCode() {
            return this.code;
        }

        public String getName() {
            return this.name;
        }

        public static SwitchActionEnum getByCode(Integer code) {
            SwitchActionEnum[] values = values();
            for (SwitchActionEnum item : values) {
                if (Objects.equals(item.getCode(), code)) {
                    return item;
                }
            }
            return null;
        }

        public static String getNameByCode(Integer code) {
            SwitchActionEnum[] values = values();
            for (SwitchActionEnum item : values) {
                if (Objects.equals(item.getCode(), code)) {
                    return item.name;
                }
            }
            return code == null ? null : code.toString();
        }

        public static Integer getCodeByName(String name) {
            SwitchActionEnum[] values = values();
            for (SwitchActionEnum item : values) {
                if (Objects.equals(item.getName(), name)) {
                    return item.code;
                }
            }
            return null;
        }
    }

    /**
     * 保护投退 (0-退出 1-投入）
     */
    public enum ProtectionActivationEnum {
        /**
         * 告警
         */
        EXIt(0, "退出"),

        /**
         * 跳闸
         */
        ENTER(1, "投入");

        final Integer code;

        final String name;

        ProtectionActivationEnum(Integer code, String name) {
            this.code = code;
            this.name = name;
        }

        public Integer getCode() {
            return this.code;
        }

        public String getName() {
            return this.name;
        }

        public static ProtectionActivationEnum getByCode(Integer code) {
            ProtectionActivationEnum[] values = values();
            for (ProtectionActivationEnum item : values) {
                if (Objects.equals(item.getCode(), code)) {
                    return item;
                }
            }
            return null;
        }

        public static String getNameByCode(Integer code) {
            ProtectionActivationEnum[] values = values();
            for (ProtectionActivationEnum item : values) {
                if (Objects.equals(item.getCode(), code)) {
                    return item.name;
                }
            }
            return code == null ? null : code.toString();
        }

        public static Integer getCodeByName(String name) {
            ProtectionActivationEnum[] values = values();
            for (ProtectionActivationEnum item : values) {
                if (Objects.equals(item.getName(), name)) {
                    return item.code;
                }
            }
            return null;
        }
    }

    /**
     * 开关隐患类型.1-存在缺陷，2-开关调试，3-告警,desc:“开始检修、停止告警”，“开关调试”，“无配置”
     */
    public enum HazardTypeEnum {
        /**
         * 存在缺陷
         */
        DEFECTS("1", "存在缺陷","开始检修、停止告警"),

        /**
         * 开关调试
         */
        SWITCH_COMMISSIONING("2", "开关调试","开关调试"),
        /**
         * 告警
         */
        ALERT("3", "告警","无配置");

        final String code;

        final String name;

        final String desc;

        HazardTypeEnum(String code, String name,String desc) {
            this.code = code;
            this.name = name;
            this.desc = desc;
        }

        public String getCode() {
            return this.code;
        }

        public String getName() {
            return this.name;
        }

        public String getDesc() {
            return this.desc;
        }

        public static HazardTypeEnum getByCode(String code) {
            HazardTypeEnum[] values = values();
            for (HazardTypeEnum item : values) {
                if (Objects.equals(item.getCode(), code)) {
                    return item;
                }
            }
            return null;
        }

        public static String getNameByCode(String code) {
            HazardTypeEnum[] values = values();
            for (HazardTypeEnum item : values) {
                if (Objects.equals(item.getCode(), code)) {
                    return item.name;
                }
            }
            return code ;
        }

        public static String getCodeByName(String name) {
            HazardTypeEnum[] values = values();
            for (HazardTypeEnum item : values) {
                if (Objects.equals(item.getName(), name)) {
                    return item.code;
                }
            }
            return null;
        }

        public static String getDescByCode(String code) {
            HazardTypeEnum[] values = values();
            for (HazardTypeEnum item : values) {
                if (Objects.equals(item.getCode(), code)) {
                    return item.desc;
                }
            }
            return null;
        }

        public static String getDescByName(String name) {
            HazardTypeEnum[] values = values();
            for (HazardTypeEnum item : values) {
                if (Objects.equals(item.getName(), name)) {
                    return item.desc;
                }
            }
            return null;
        }

    }
}
