package cn.axzo.msg.center.notices.common.enums;

import cn.azxo.framework.common.model.EnumBase;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * 消息状态枚举类
 *
 * @author zhaoyong_sh
 * @see MessageStatusEnum
 * @since 2021-05-19 18:17
 */
@RequiredArgsConstructor
@Getter
public enum MessageStatusEnum implements EnumBase<String> {

    /**
     * 消息状态枚举类
     */
    INIT("INIT", "初始化"),
    PROCESSING("PROCESSING", "处理中"),
    EXCEPTION("EXCEPTION", "处理异常"),
    FAIL("FAIL", "处理失败"),
    SUCCESS("SUCCESS", "成功"),
    ;

    private final String code;

    private final String message;

    public static MessageStatusEnum getByCode(String code) {
        if(StringUtils.isBlank(code)) {
            return null;
        }
        for (MessageStatusEnum statusEnum : MessageStatusEnum.values()) {
            if (statusEnum.getCode().equals(code)) {
                return statusEnum;
            }
        }
        return null;
    }

    public static String getSuccessCode(Boolean isSuccess) {

        if (Objects.isNull(isSuccess)) {
            return null;
        }
        if (isSuccess){
            return SUCCESS.getCode();
        }
        return FAIL.getCode();
    }
}
