from _typeshed import Incomplete
from collections.abc import Iterator
from types import TracebackType
from typing_extensions import Self

from .errors import DirtyError

class StashError(DirtyError): ...

class StashTableNotFoundError(StashError):
    table_name: str

    def __init__(self, table_name: str) -> None: ...

class StashKeyNotFoundError(StashError):
    table_name: str
    key: str

    def __init__(self, table_name: str, key: str) -> None: ...

class StashClient:
    socket_path: str
    timeout: float

    def __init__(self, socket_path: str, timeout: float = 30.0) -> None: ...
    def put(self, table: str, key: str, value) -> None: ...
    def get(self, table: str, key: str, default=None): ...
    def delete(self, table: str, key: str) -> bool: ...
    def keys(self, table: str, pattern: str | None = None) -> list[str]: ...
    def clear(self, table: str) -> None: ...
    def info(self, table: str) -> dict[str, Incomplete]: ...
    def ensure(self, table: str) -> None: ...
    def exists(self, table: str, key=None) -> bool: ...
    def delete_table(self, table: str) -> None: ...
    def tables(self) -> list[str]: ...
    def table(self, name: str) -> StashTable: ...
    def close(self) -> None: ...
    def __enter__(self) -> Self: ...
    def __exit__(
        self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
    ) -> None: ...

class StashTable:
    def __init__(self, client: StashClient, name: str) -> None: ...
    @property
    def name(self) -> str: ...
    def __getitem__(self, key: str): ...
    def __setitem__(self, key: str, value) -> None: ...
    def __delitem__(self, key: str) -> None: ...
    def __contains__(self, key: str) -> bool: ...
    def __iter__(self) -> Iterator[str]: ...
    def __len__(self) -> int: ...
    def get(self, key: str, default=None): ...
    def keys(self, pattern: str | None = None) -> list[str]: ...
    def clear(self) -> None: ...
    def items(self) -> Iterator[tuple[Incomplete, Incomplete]]: ...
    def values(self) -> Iterator[Incomplete]: ...

def set_stash_socket_path(path: str) -> None: ...
def get_stash_socket_path() -> str: ...
def put(table: str, key: str, value) -> None: ...
def get(table: str, key: str, default=None): ...
def delete(table: str, key: str) -> bool: ...
def keys(table: str, pattern: str | None = None) -> list[str]: ...
def clear(table: str) -> None: ...
def info(table: str) -> dict[str, Incomplete]: ...
def ensure(table: str) -> None: ...
def exists(table: str, key: str | None = None) -> bool: ...
def delete_table(table: str) -> None: ...
def tables() -> list[str]: ...
def table(name: str) -> StashTable: ...
