package tech.easyflow.ai.invoke.exception;

public class ModelInvokeException extends RuntimeException {

    private final int status;
    private final String type;
    private final String param;
    private final String code;

    public ModelInvokeException(int status, String message, String type, String param, String code) {
        super(message);
        this.status = status;
        this.type = type;
        this.param = param;
        this.code = code;
    }

    public int getStatus() {
        return status;
    }

    public String getType() {
        return type;
    }

    public String getParam() {
        return param;
    }

    public String getCode() {
        return code;
    }

    public static ModelInvokeException badRequest(String message) {
        return badRequest(message, null, "invalid_request_error");
    }

    public static ModelInvokeException badRequest(String message, String param, String code) {
        return new ModelInvokeException(400, message, "invalid_request_error", param, code);
    }

    public static ModelInvokeException unauthorized(String message) {
        return new ModelInvokeException(401, message, "authentication_error", null, "unauthorized");
    }

    public static ModelInvokeException forbidden(String message) {
        return new ModelInvokeException(403, message, "permission_error", null, "forbidden");
    }

    public static ModelInvokeException notFound(String message) {
        return new ModelInvokeException(404, message, "not_found_error", "model", "model_not_found");
    }

    public static ModelInvokeException badGateway(String message) {
        return new ModelInvokeException(502, message, "api_error", null, "upstream_bad_gateway");
    }

    public static ModelInvokeException serviceUnavailable(String message) {
        return new ModelInvokeException(503, message, "service_unavailable_error", null, "upstream_unavailable");
    }
}
