package com.yuchen.saas.park.service.util;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum ResultCodeEnum {

    SUCCESS(200, "操作成功"),
    FAILURE(400, "业务异常"),
    UN_AUTHORIZED(401, "请求未授权"),
    CLIENT_UN_AUTHORIZED(401, "客户端请求未授权"),
    NOT_FOUND(404, "404 没找到请求"),
    MSG_NOT_READABLE(400, "消息不能读取"),
    METHOD_NOT_SUPPORTED(405, "不支持当前请求方法"),
    MEDIA_TYPE_NOT_SUPPORTED(415, "不支持当前媒体类型"),
    REQ_REJECT(403, "请求被拒绝"),
    INTERNAL_SERVER_ERROR(500, "服务器异常"),
    CUSTOMIZE(500, ""),
    PARAM_MISS(400, "缺少必要的请求参数"),
    PARAM_TYPE_ERROR(400, "请求参数类型错误"),
    PARAM_BIND_ERROR(400, "请求参数绑定错误"),
    NULL_POINTER_ERROR(400, "调用了未经初始化的对象或者是不存在的对象"),
    RECORD_EXITED_ERROR(400, "数据库已存在该条记录"),
    PARAM_VALID_ERROR(400, "参数校验失败"),
    TOKEN_PAST(401, "身份过期，请重新登陆"),
    AUTH_FAIL(400, "认证失败"),
    UNAUTHORIZED(401, "请先通过身份认证"),
    TOKEN_ERROR(402, "令牌错误"),
    HEADER_ERROR(403, "请求头错误"),
    AUTH_USERNAME_NONE(405, "用户名不能为空"),
    AUTH_PASSWORD_NONE(406, "数码不能为空");

    public Integer code;
    public String message;

    public static ResultCodeEnum getCode(Integer code) {
        ResultCodeEnum[] resultCodes = ResultCodeEnum.values();
        for (ResultCodeEnum resultCode : resultCodes) {
            if (code.intValue() == resultCode.code.intValue()) {
                return resultCode;
            }
        }
        return null;
    }

    public static String getValue(Integer code) {
        ResultCodeEnum[] resultCodes = ResultCodeEnum.values();
        for (ResultCodeEnum resultCode : resultCodes) {
            if (code.intValue() == resultCode.code.intValue()) {
                return resultCode.message;
            }
        }
        return "";
    }
}
