package com.zhyc.module.biosafety.enums;

/**
 * 检疫结果枚举
 */
public enum QuarantineResult {

    NEGATIVE(0, "阴性"),
    POSITIVE(1, "阳性");

    private final int code;
    private final String desc;

    QuarantineResult(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据code获取描述
     */
    public static String getDescByCode(Integer code) {
        if (code == null) {
            return "";
        }
        for (QuarantineResult result : values()) {
            if (result.code == code) {
                return result.desc;
            }
        }
        return "";
    }

    /**
     * 根据code获取枚举
     */
    public static QuarantineResult getByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (QuarantineResult result : values()) {
            if (result.code == code) {
                return result;
            }
        }
        return null;
    }

    /**
     * 根据描述获取code
     */
    public static Integer getCodeByDesc(String desc) {
        if (desc == null || desc.trim().isEmpty()) {
            return null;
        }
        for (QuarantineResult result : values()) {
            if (result.desc.equals(desc)) {
                return result.code;
            }
        }
        return null;
    }
}