from typing import Any, Dict, List, Optional, Union
import httpx

class GraphQLClientError(Exception):
    """@private
Base exception."""

class GraphQLClientHttpError(GraphQLClientError):
    """@private"""

    def __init__(self, status_code: int, response: httpx.Response) -> None:
        self.status_code = status_code
        self.response = response

    def __str__(self) -> str:
        return f'HTTP status code: {self.status_code}'

class GraphQLClientInvalidResponseError(GraphQLClientError):
    """@private"""

    def __init__(self, response: httpx.Response) -> None:
        self.response = response

    def __str__(self) -> str:
        return 'Invalid response format.'

class GraphQLClientGraphQLError(GraphQLClientError):
    """@private"""

    def __init__(self, message: str, locations: Optional[List[Dict[str, int]]]=None, path: Optional[List[str]]=None, extensions: Optional[Dict[str, object]]=None, original: Optional[Dict[str, object]]=None):
        self.message = message
        self.locations = locations
        self.path = path
        self.extensions = extensions
        self.original = original

    def __str__(self) -> str:
        return self.message

    @classmethod
    def from_dict(cls, error: Dict[str, Any]) -> 'GraphQLClientGraphQLError':
        return cls(message=error['message'], locations=error.get('locations'), path=error.get('path'), extensions=error.get('extensions'), original=error)

class GraphQLClientGraphQLMultiError(GraphQLClientError):
    """@private"""

    def __init__(self, errors: List[GraphQLClientGraphQLError], data: Optional[Dict[str, Any]]=None):
        self.errors = errors
        self.data = data

    def __str__(self) -> str:
        return '; '.join((str(e) for e in self.errors))

    @classmethod
    def from_errors_dicts(cls, errors_dicts: List[Dict[str, Any]], data: Optional[Dict[str, Any]]=None) -> 'GraphQLClientGraphQLMultiError':
        return cls(errors=[GraphQLClientGraphQLError.from_dict(e) for e in errors_dicts], data=data)

class GraphQLClientInvalidMessageFormat(GraphQLClientError):
    """@private"""

    def __init__(self, message: Union[str, bytes]) -> None:
        self.message = message

    def __str__(self) -> str:
        return 'Invalid message format.'