package cn.novalon.gym.manage.common.exception;

import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

public abstract class BaseException extends RuntimeException {

    private final String errorCode;
    private final Map<String, Object> context;

    protected BaseException(String errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
        this.context = new HashMap<>();
    }

    protected BaseException(String errorCode, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
        this.context = new HashMap<>();
    }

    public String getErrorCode() {
        return errorCode;
    }

    public Map<String, Object> getContext() {
        return context;
    }

    public BaseException addContext(String key, Object value) {
        context.put(key, value);
        return this;
    }

    public abstract HttpStatus getHttpStatus();
}
