package com.qmth.jkserver.core.exception;

import org.springframework.http.HttpStatus;

/**
 * 系统异常信息
 *
 * @author tianjun
 */
public class JkServerException extends RuntimeException {

    private static final long serialVersionUID = -8007657202243426183L;

    public static final JkServerException SYSTEM_EXCEPTION = new JkServerException(-500, "系统错误");
    public static final JkServerException LOGIN_NEEDED = new JkServerException(-501, "无法获取到用户登录信息,请登录");
    public static final JkServerException EXAM_CODE_INVALID = new JkServerException(-502, "考试识别码错误");
    public static final JkServerException DECODE_ANSWER_FILE_ERROR = new JkServerException(-503, "解码答案文件失败");
    public static final JkServerException FILE_MD5_NOT_MATCH = new JkServerException(-504, "文件MD5校验失败");
    public static final JkServerException NOT_FILE_UPLOAD_REQUEST = new JkServerException(-505, "不是文件上传的请求");
    public static final JkServerException FILE_UPLOAD_ERROR = new JkServerException(-506, "文件上传失败");
    public static final JkServerException EXAM_PLAN_UN_PUBLISHED = new JkServerException(-507, "考试计划没有发布");
    public static final JkServerException FILED_VALIDATE_ERROR = new JkServerException(-666, "字段校验错误");
    public static final JkServerException EXAM_CODE_IS_NULL = new JkServerException(-508, "考试识别码为null值");
    public static final JkServerException ANSWER_UPLOAD_CONFILCT = new JkServerException(-509, "不能够同时上传同一个考场的数据,答案上传冲突了");
    public static final JkServerException EXAM_PLAN_NAME_ALREADY_EXISTS = new JkServerException(-510, "考试计划的名字已经存在");
    public static final JkServerException MISSING_INI_OR_AUDIO_FILE = new JkServerException(-511, "考生视唱答案包中缺少INI或者音频文件");
    public static final JkServerException SOLFEGE_ANSWER_ERROR = new JkServerException(-512, "视唱答案结构错误");
    public static final JkServerException STUDENT_ANSWER_UPLOAD_CONFILCT = new JkServerException(-513, "不能够同时上传同一个考生的数据,答案上传冲突了");
    public static final JkServerException AUTH_INFO_ERROR = new JkServerException(4010009, "系统授权信息已过期，请联系系统管理员激活!");
    public static final JkServerException LOGIN_ERROR = new JkServerException(-4010010, "身份验证失效，请重新登录");

    private int code;

    private String message;

    public JkServerException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public JkServerException(String message) {
        this(SYSTEM_EXCEPTION.getCode(), message);
    }

    public int getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public static JkServerException withFieldValidateError(String message) {
        return new JkServerException(FILED_VALIDATE_ERROR.getCode(), message);
    }

    public static JkServerException withMessage(String message) {
        return new JkServerException(SYSTEM_EXCEPTION.getCode(), message);
    }

}
