from typing import Any, Dict, Generic, Iterator, Tuple, TypeVar

from botocore.exceptions import EventStreamError as EventStreamError
from botocore.model import StructureShape
from botocore.parsers import BaseEventStreamParser

_T = TypeVar("_T")

class ParserError(Exception): ...

class DuplicateHeader(ParserError):
    def __init__(self, header: str) -> None: ...

class InvalidHeadersLength(ParserError):
    def __init__(self, length: int) -> None: ...

class InvalidPayloadLength(ParserError):
    def __init__(self, length: int) -> None: ...

class ChecksumMismatch(ParserError):
    def __init__(self, expected: int, calculated: int) -> None: ...

class NoInitialResponseError(ParserError):
    def __init__(self) -> None: ...

class DecodeUtils:
    UINT8_BYTE_FORMAT: str = ...
    UINT16_BYTE_FORMAT: str = ...
    UINT32_BYTE_FORMAT: str = ...
    INT8_BYTE_FORMAT: str = ...
    INT16_BYTE_FORMAT: str = ...
    INT32_BYTE_FORMAT: str = ...
    INT64_BYTE_FORMAT: str = ...
    PRELUDE_BYTE_FORMAT: str = ...
    UINT_BYTE_FORMAT: Dict[int, str] = ...
    @staticmethod
    def unpack_true(data: bytes) -> Tuple[bool, int]: ...
    @staticmethod
    def unpack_false(data: bytes) -> Tuple[bool, int]: ...
    @staticmethod
    def unpack_uint8(data: bytes) -> Tuple[int, int]: ...
    @staticmethod
    def unpack_uint32(data: bytes) -> Tuple[int, int]: ...
    @staticmethod
    def unpack_int8(data: bytes) -> Tuple[int, int]: ...
    @staticmethod
    def unpack_int16(data: bytes) -> Tuple[int, int]: ...
    @staticmethod
    def unpack_int32(data: bytes) -> Tuple[int, int]: ...
    @staticmethod
    def unpack_int64(data: bytes) -> Tuple[int, int]: ...
    @staticmethod
    def unpack_byte_array(data: bytes, length_byte_size: int = ...) -> Tuple[bytes, int]: ...
    @staticmethod
    def unpack_utf8_string(data: bytes, length_byte_size: int = ...) -> Tuple[str, int]: ...
    @staticmethod
    def unpack_uuid(data: bytes) -> Tuple[bytes, int]: ...
    @staticmethod
    def unpack_prelude(data: bytes) -> Tuple[Tuple[int, int, int], int]: ...

class MessagePrelude:
    def __init__(self, total_length: int, headers_length: int, crc: int) -> None:
        self.total_length: int = ...
        self.headers_length: int = ...
        self.crc: int = ...
    @property
    def payload_length(self) -> int: ...
    @property
    def payload_end(self) -> int: ...
    @property
    def headers_end(self) -> int: ...

class EventStreamMessage:
    def __init__(self, prelude: int, headers: int, payload: bytes, crc: int) -> None:
        self.prelude: int = ...
        self.headers: int = ...
        self.payload: bytes = ...
        self.crc: int = ...
    def to_response_dict(self, status_code: int = ...) -> Dict[str, Any]: ...

class EventStreamHeaderParser:
    def __init__(self) -> None: ...
    def parse(self, data: bytes) -> Dict[str, Any]: ...

class EventStreamBuffer:
    def __init__(self) -> None: ...
    def add_data(self, data: bytes) -> None: ...
    def next(self) -> EventStreamMessage: ...
    def __next__(self) -> EventStreamMessage: ...
    def __iter__(self: _T) -> _T: ...

class EventStream(Generic[_T]):
    def __init__(
        self,
        raw_stream: Any,
        output_shape: StructureShape,
        parser: BaseEventStreamParser,
        operation_name: str,
    ) -> None: ...
    def __iter__(self) -> Iterator[_T]: ...
    def get_initial_response(self) -> _T: ...
    def close(self) -> None: ...
