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),
        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),
        USERNAME_PASSWORD_ERROR(40303),
        USER_EXIST(40304),
        PERMISSION_ERROR(40401),
        DEVICE_ERROR(40501),
        DEVICE_VERSION_ERROR(40502);

        private int value;

        ErrorResultCodeEnum(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }
}
