package com.storlead.sales.mail.enums;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

@Getter
public enum EmailFolderlRuleEnum {
    EMAIL_FROM_EQ("EMAIL_FROM_EQ", "发件箱等于"),
    EMAIL_SUBJECT_CONTAINS("EMAIL_SUBJECT_CONTAINS", "邮件主题包含"),
    EMAIL_FROM_SUFFIX_EQ("EMAIL_FROM_SUFFIX_EQ", "发件邮箱后缀等于")
    ;

    /**
     * {@link EnumValue}标记数据库存的值是code
     */
    @EnumValue
    public String code;

    /**
     * {@link JsonValue} 标记json返回给前端显示的值是desc
     */
    @JsonValue
    public String desc;

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

    public static EmailBoxEnum getEnumByCode(String code) {
        if (StrUtil.isBlank(code)) {
            return null;
        }
        for (EmailBoxEnum type : EmailBoxEnum.values()) {
            if (type.code.equals(code)) {
                return type;
            }
        }
        return null;
    }

    public static String getEnumNameByCode(String code) {
        if (StrUtil.isBlank(code)) {
            return "";
        }
        for (EmailBoxEnum type : EmailBoxEnum.values()) {
            if (type.code.equals(code)) {
                return type.desc;
            }
        }
        return null;
    }

}
