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

import cn.axzo.msg.center.notices.common.exception.BizException;
import cn.azxo.framework.common.model.EnumBase;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 查询阿里云发送详情状态枚举
 *
 * @author zhaoyong_sh
 * @see SendDetailsStatusEnum
 * @since 2021-05-19 15:00
 */
@RequiredArgsConstructor
@Getter
public enum SendDetailsStatusEnum implements EnumBase<Long> {

    /**
     * 发送短信状态
     */
    WAIT_RECEIPT(1L, "等待回执"),
    FAIL(2L, "发送失败"),
    SUCCESS(3L, "发送成功"),
    ;

    private final Long code;

    private final String message;

    public static SendDetailsStatusEnum getByCode(Long code) {
        if(code == null) {
            return null;
        }
        for (SendDetailsStatusEnum statusEnum : SendDetailsStatusEnum.values()) {
            if (statusEnum.getCode().equals(code)) {
                return statusEnum;
            }
        }
        return null;
    }

    public static String getMappingCode(SendDetailsStatusEnum statusEnum) {
        if(WAIT_RECEIPT == statusEnum) {
            return MessageStatusEnum.PROCESSING.getCode();
        }
        if(FAIL == statusEnum) {
            return MessageStatusEnum.FAIL.getCode();
        }
        if(SUCCESS == statusEnum) {
            return MessageStatusEnum.SUCCESS.getCode();
        }
        throw new BizException(ReturnCodeEnum.SYSTEM_ERROR, "status enum must not be null");
    }


}
