import abc
from typing import Any
from typing import Optional

from .result import Result as Result
from .result import ResultMetaData as ResultMetaData
from .result import SimpleResultMetaData as SimpleResultMetaData
from .result import tuplegetter as tuplegetter
from .row import LegacyRow as LegacyRow
from .. import exc as exc
from .. import util as util
from ..sql import expression as expression
from ..sql import sqltypes as sqltypes
from ..sql.compiler import RM_NAME as RM_NAME
from ..sql.compiler import RM_OBJECTS as RM_OBJECTS
from ..sql.compiler import RM_RENDERED_NAME as RM_RENDERED_NAME
from ..sql.compiler import RM_TYPE as RM_TYPE

MD_INDEX: int
MD_RESULT_MAP_INDEX: int
MD_OBJECTS: int
MD_LOOKUP_KEY: int
MD_RENDERED_NAME: int
MD_PROCESSOR: int
MD_UNTRANSLATED: int

class CursorResultMetaData(ResultMetaData):
    returns_rows: bool = ...
    case_sensitive: Any = ...
    def __init__(self, parent: Any, cursor_description: Any) -> None: ...

class LegacyCursorResultMetaData(CursorResultMetaData): ...

class ResultFetchStrategy:
    alternate_cursor_description: Any = ...
    def soft_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def hard_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def yield_per(self, result: Any, dbapi_cursor: Any, num: Any) -> None: ...
    def fetchone(
        self, result: Any, dbapi_cursor: Any, hard_close: bool = ...
    ) -> None: ...
    def fetchmany(
        self, result: Any, dbapi_cursor: Any, size: Optional[Any] = ...
    ) -> None: ...
    def fetchall(self, result: Any) -> None: ...
    def handle_exception(
        self, result: Any, dbapi_cursor: Any, err: Any
    ) -> None: ...

class NoCursorFetchStrategy(ResultFetchStrategy):
    def soft_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def hard_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def fetchone(
        self, result: Any, dbapi_cursor: Any, hard_close: bool = ...
    ): ...
    def fetchmany(
        self, result: Any, dbapi_cursor: Any, size: Optional[Any] = ...
    ): ...
    def fetchall(self, result: Any, dbapi_cursor: Any): ...

class NoCursorDQLFetchStrategy(NoCursorFetchStrategy): ...
class NoCursorDMLFetchStrategy(NoCursorFetchStrategy): ...

class CursorFetchStrategy(ResultFetchStrategy):
    def soft_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def hard_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def handle_exception(
        self, result: Any, dbapi_cursor: Any, err: Any
    ) -> None: ...
    def yield_per(self, result: Any, dbapi_cursor: Any, num: Any) -> None: ...
    def fetchone(
        self, result: Any, dbapi_cursor: Any, hard_close: bool = ...
    ): ...
    def fetchmany(
        self, result: Any, dbapi_cursor: Any, size: Optional[Any] = ...
    ): ...
    def fetchall(self, result: Any, dbapi_cursor: Any): ...

class BufferedRowCursorFetchStrategy(CursorFetchStrategy):
    def __init__(
        self,
        dbapi_cursor: Any,
        execution_options: Any,
        growth_factor: int = ...,
        initial_buffer: Optional[Any] = ...,
    ) -> None: ...
    @classmethod
    def create(cls, result: Any): ...
    def yield_per(self, result: Any, dbapi_cursor: Any, num: Any) -> None: ...
    def soft_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def hard_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def fetchone(
        self, result: Any, dbapi_cursor: Any, hard_close: bool = ...
    ): ...
    def fetchmany(
        self, result: Any, dbapi_cursor: Any, size: Optional[Any] = ...
    ): ...
    def fetchall(self, result: Any, dbapi_cursor: Any): ...

class FullyBufferedCursorFetchStrategy(CursorFetchStrategy):
    alternate_cursor_description: Any = ...
    def __init__(
        self,
        dbapi_cursor: Any,
        alternate_description: Optional[Any] = ...,
        initial_buffer: Optional[Any] = ...,
    ) -> None: ...
    def yield_per(self, result: Any, dbapi_cursor: Any, num: Any) -> None: ...
    def soft_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def hard_close(self, result: Any, dbapi_cursor: Any) -> None: ...
    def fetchone(
        self, result: Any, dbapi_cursor: Any, hard_close: bool = ...
    ): ...
    def fetchmany(
        self, result: Any, dbapi_cursor: Any, size: Optional[Any] = ...
    ): ...
    def fetchall(self, result: Any, dbapi_cursor: Any): ...

class _NoResultMetaData(ResultMetaData):
    returns_rows: bool = ...
    @property
    def keys(self) -> None: ...

class BaseCursorResult:
    out_parameters: Any = ...
    closed: bool = ...
    context: Any = ...
    dialect: Any = ...
    cursor: Any = ...
    cursor_strategy: Any = ...
    connection: Any = ...
    def __init__(
        self, context: Any, cursor_strategy: Any, cursor_description: Any
    ): ...
    @property
    def inserted_primary_key_rows(self): ...
    @property
    def inserted_primary_key(self): ...
    def last_updated_params(self): ...
    def last_inserted_params(self): ...
    @property
    def returned_defaults_rows(self): ...
    @property
    def returned_defaults(self): ...
    def lastrow_has_defaults(self): ...
    def postfetch_cols(self): ...
    def prefetch_cols(self): ...
    def supports_sane_rowcount(self): ...
    def supports_sane_multi_rowcount(self): ...
    def rowcount(self): ...
    @property
    def lastrowid(self): ...
    @property
    def returns_rows(self): ...
    @property
    def is_insert(self): ...

class CursorResult(BaseCursorResult, Result):
    def merge(self, *others: Any): ...
    def close(self) -> None: ...
    def yield_per(self, num: Any) -> None: ...

class LegacyCursorResult(CursorResult):
    def close(self) -> None: ...

ResultProxy = LegacyCursorResult

class BufferedRowResultProxy(ResultProxy): ...
class FullyBufferedResultProxy(ResultProxy): ...
class BufferedColumnRow(LegacyRow, metaclass=abc.ABCMeta): ...
class BufferedColumnResultProxy(ResultProxy): ...
