package com.storlead.sales.mail.enums;

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

/**
 * @program: sp-sales-platform
 * @description:
 * @author: chenkq
 * @create: 2024-07-18 14:44
 */
public enum EmailBoxEnum {
    INBOX("INBOX", "收件箱"),
    SENT("SENT", "已发送"),
    SENTING("SENTING", "发件箱"),
    STARRED("STARRED", "星标"),
    DRAFT("DRAFT", "草稿箱"),
    TRASH("TRASH", "垃圾箱")
    ;

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

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

    EmailBoxEnum(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;
    }
}
