package cn.meowrain.aioj.backend.auth.oauth2.exception;

/**
 * OAuth2 异常基类 用于统一处理 OAuth2 相关的异常
 *
 * @author meowrain
 * @since 2025-12-14
 */
public class OAuth2Exception extends RuntimeException {

	private final String error;

	private final String errorDescription;

	private final int httpStatus;

	/**
	 * 构造函数
	 * @param error 错误代码（符合 OAuth2 规范）
	 * @param errorDescription 错误描述
	 */
	public OAuth2Exception(String error, String errorDescription) {
		super(errorDescription);
		this.error = error;
		this.errorDescription = errorDescription;
		this.httpStatus = 400; // 默认 400 Bad Request
	}

	/**
	 * 构造函数（带 HTTP 状态码）
	 * @param error 错误代码
	 * @param errorDescription 错误描述
	 * @param httpStatus HTTP 状态码
	 */
	public OAuth2Exception(String error, String errorDescription, int httpStatus) {
		super(errorDescription);
		this.error = error;
		this.errorDescription = errorDescription;
		this.httpStatus = httpStatus;
	}

	/**
	 * 简化构造函数（仅错误描述）
	 * @param errorDescription 错误描述
	 */
	public OAuth2Exception(String errorDescription) {
		this("invalid_request", errorDescription);
	}

	public String getError() {
		return error;
	}

	public String getErrorDescription() {
		return errorDescription;
	}

	public int getHttpStatus() {
		return httpStatus;
	}

}
