package com.njcn.gather.result.pojo.enums;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

/**
 * @author caozehui
 * @data 2024/11/9
 */
@Getter
public enum ResultUnitEnum {

    FREQ("Hz", "频率","FREQ"),
    V_RELATIVE("%Un", "电压","V"),
    V_ABSOLUTELY("V", "电压","V"),
    I_RELATIVE("%In", "电流","I"),
    I_ABSOLUTELY("A", "电流","I"),
    HV("%", "谐波电压","HV"),
    HI("%", "谐波电流","HI"),
    HP("W", "谐波有功功率","HP"),
    HSV("%", "间谐波电压","HSV"),
    HSI("%", "间谐波电流","HSI"),
    VOLTAGE_MAG("周波", "暂态持续时间","VOLTAGE"),
    VOLTAGE_DUR("%", "暂态深度","VOLTAGE"),
    IMBV("%", "电压不平衡度","IMBV"),
    IMBA("%", "电流不平衡度","IMBA"),
    F("","闪变","F"),
    P("W", "功率","P"),
    ANGLE("°", "相角","Angle"),

    UNKNOWN("","未知","UNKNOWN"),
    ;

    private String unit;
    private String name;
    private String code;

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

    public static ResultUnitEnum getResultUnitEnumByCode(String code) {
        for (ResultUnitEnum resultUnitEnum : ResultUnitEnum.values()) {
            if (ObjectUtil.equals(code, resultUnitEnum.getCode())) {
                return resultUnitEnum;
            }
        }
        return UNKNOWN;
    }
}
