from pydantic import BaseModel


class RpcClientError(Exception):
    """Base error for all NEAR client related failures."""
    pass


class RpcTransportError(RpcClientError):
    """Network-level errors (timeout, DNS, connection, etc)."""
    pass


class RpcHttpError(RpcClientError):
    """Non-200 HTTP responses."""

    def __init__(self, status_code: int, body: str | None = None):
        self.status_code = status_code
        self.body = body
        super().__init__(f"HTTP error {status_code}")


class RpcError(RpcClientError):
    """JSON-RPC error object wrapping the Pydantic error model."""

    def __init__(self, error: BaseModel | str):
        self.error = error

        if isinstance(error, BaseModel):
            super().__init__(getattr(error, "message", "RPC Error"))
        else:
            super().__init__(error)


class RpcTimeoutError(RpcClientError):
    """Timeout Error"""

    def __init__(self):
        super().__init__("Timeout Error")
