package thyyxxk.webserver.constants.sidicts;

import thyyxxk.webserver.utils.StringUtil;

/**
 * @description: 就诊凭证类型
 * @author: DingJie
 * @create: 2021/7/129:17
 */
public enum MdtrtCertType {

    MEDICAL_INSURANCE_ELECTRONIC_VOUCHER("01", "医保电子凭证", "qrcode"),
    MEDICAL_INSURANCE_ELECTRONIC_VOUCHER2("01", "医保电子凭证", "qrcode2"),
    MEDICAL_INSURANCE_ELECTRONIC_VOUCHER3("01", "刷脸", "face"),
    RESIDENT_IDENTITY_CARD("02", "居民身份证", "idcard"),
    RESIDENT_IDENTITY_CARD2("02", "居民身份证", "idcard2"),
    SOCIAL_SECURITY_CARD("03", "社会保障卡", "sicard"),
    SHOUD_BE_QR("04", "刷脸", "04"),
    OTHER("99", "其他", "other");

    private final String code;
    private final String name;
    private final String label;

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

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public String getLabel() {
        return label;
    }

    public static MdtrtCertType get(String code) {
        if (StringUtil.isBlank(code)) {
            return null;
        }
        for (MdtrtCertType mdtrtCertType : MdtrtCertType.values()) {
            if (code.trim().equals(mdtrtCertType.getCode())) {
                if (mdtrtCertType == SHOUD_BE_QR) {
                    return MEDICAL_INSURANCE_ELECTRONIC_VOUCHER;
                }
                return mdtrtCertType;
            }
        }
        return null;
    }

    public static MdtrtCertType getByLabel(String label) {
        if (StringUtil.isBlank(label)) {
            return RESIDENT_IDENTITY_CARD;
        }
        for (MdtrtCertType mdtrtCertType : MdtrtCertType.values()) {
            if (label.trim().equals(mdtrtCertType.getLabel())) {
                if (mdtrtCertType == SHOUD_BE_QR) {
                    return MEDICAL_INSURANCE_ELECTRONIC_VOUCHER;
                }
                return mdtrtCertType;
            }
        }
        return RESIDENT_IDENTITY_CARD;
    }
}
