package com.storlead.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-11-05 09:26
 */
public enum EmailFileFolderEnum {
    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;

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

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

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