package com.zhyc.module.biosafety.enums;


/**
 * 处方类型枚举
 */
public enum PrescriptionType {

    IMMUNITY(0, "免疫"),
    DEWORMING(1, "驱虫"),
    HEALTH_CARE(2, "保健"),
    DISINFECTION(3, "消毒"),
    DISEASE_TREATMENT(4, "疾病治疗");

    private final int code;
    private final String desc;

    PrescriptionType(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 (PrescriptionType type : values()) {
            if (type.code == code) {
                return type.desc;
            }
        }
        return "";
    }

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

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