package ink.wgink.pojo.result;

import java.io.Serializable;

/**
 * @ClassName: ErrorResult
 * @Description: 错误结果
 * @Author: WangGeng
 * @Date: 2019/3/2 3:37 PM
 * @Version: 1.0
 **/
public class ErrorResult implements Serializable {

    private Integer code;
    private String msg;
    private String detail;

    public ErrorResult() {
    }

    public ErrorResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getDetail() {
        return detail == null ? "" : detail.trim();
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"code\":")
                .append(code);
        sb.append(",\"msg\":\"")
                .append(msg).append('\"');
        sb.append(",\"detail\":\"")
                .append(detail).append('\"');
        sb.append('}');
        return sb.toString();
    }

    public enum ErrorResultCodeEnum {

        /**
         * 错误类型
         */
        SYSTEM_ERROR(40001, "系统错误"),
        ENCODE_ERROR(40002, "编码错误"),
        DECODE_ERROR(40003, "解码错误"),
        APP_DEPENDENCY_ERROR(40004, "APP依赖错误"),
        PROPERTIES_ERROR(40005, "配置属性错误"),
        TEXT_ILLEGAL(40101, "文本非法"),
        PARAMS_ERROR(40102, "参数错误"),
        QUERY_ERROR(40101, "查询错误"),
        SAVE_ERROR(40102, "保存错误"),
        UPDATE_ERROR(40103, "更新错误"),
        REMOVE_ERROR(40104, "删除错误"),
        FILE_ERROR(40401, "文件错误"),
        TEST_ERROR(40201, "测试错误"),
        LOGIN_OUT(40301, "登录登出"),
        TOKEN_ERROR(40302, "TOKEN错误"),
        USERNAME_PASSWORD_ERROR(40303, "用户名密码错误"),
        USER_EXIST(40304, "用户存在"),
        DEVICE_ERROR(40501, "设备错误"),
        DEVICE_VERSION_ERROR(40502, "设备版本错误"),
        PERMISSION_ERROR(40601, "权限错误"),
        REMOTE_REQUEST_EXCEPTION(40701, "远程请求错误"),
        REMOTE_RESPONSE_EXCEPTION(40702, "远程响应错误"),
        OA_NODE_EXCEPTION(40801, "OA节点异常");


        private int value;
        private String summary;

        ErrorResultCodeEnum(int value, String summary) {
            this.value = value;
            this.summary = summary;
        }

        public int getValue() {
            return value;
        }

        public String getSummary() {
            return summary == null ? "" : summary.trim();
        }
    }
}
