package com.games.gateway.enums;

import com.games.gateway.exceptions.BizException;
import com.games.gateway.utils.MessageUtils;
import lombok.Getter;

/**
 * @description: 弹窗消息的定义
 * @author: zzhan
 * @create: 2021-12-17 10:25
 **/
@Getter
public enum BizResultCode {

    NO_LOGIN("0001", "User is not logged in"),
    DEVICE_ID_ERROR("0002", "NOT DEVICE ID"),
    SYS_OPERATOR_FAST_ERROR("", "请求太频繁"),
    //2022-11-24 临时处理，后面删掉 等android重新发布后直接将这行代码废弃掉
    APP_VERSION_ERROR("0001", ""),

    ;


    private final String errorCode;
    private final String errorMsg;

    BizResultCode(String errorCode, String errorMsg) {
        this.errorCode = getAppId() + errorCode;
        this.errorMsg = errorMsg;
    }

    /**
     * 得到 message 的值.
     *
     * @return 属性 message 的值.
     */
    public String getErrorMsg() {
        return errorMsg + "(" + getAppId() + ")";
    }

    /**
     * @return 当前服务的AppId
     */
    public String getAppId() {
        return "1005";
    }

    /**
     * 校验方法
     *
     * @param expect
     */
    public void check(boolean expect) {
        if (expect) {
            throw new BizException(this.getErrorCode(), MessageUtils.get(this.name()));
        }
    }
}
