package com.qmth.boot.core.exception;

/**
 * 通用资源不存在异常，在API层按404状态码处理
 */
public class NotFoundException extends RuntimeException implements CodeNameException {

    private static final long serialVersionUID = 648446289813795314L;

    private Integer code;

    private String name;

    /**
     * 有明确的文字提示
     *
     * @param message
     */
    public NotFoundException(String message) {
        super(message);
    }

    /**
     * 有明确的文字提示与触发来源
     *
     * @param message
     * @param cause
     */
    public NotFoundException(String message, Throwable cause) {
        super(message, cause);
    }

    /**
     * 带所有参数的构造方法
     *
     * @param code    - 数字标识，范围在100~999
     * @param name    - 异常详细类型
     * @param message - 文字提示
     * @param cause   - 触发来源
     */
    public NotFoundException(Integer code, String name, String message, Throwable cause) {
        super(message, cause);
        if (code != null) {
            if (code < 100 || code > 999) {
                throw new IllegalArgumentException("NotFoundException.code should between 100~999");
            }
        }
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }
}
