# Type stubs for the _snkv CPython extension module.
# This file enables IDE autocompletion and mypy type checking.

from typing import Optional, List, Tuple

# ---------------------------------------------------------------------------
# Constants
# ---------------------------------------------------------------------------

JOURNAL_DELETE: int
JOURNAL_WAL: int

SYNC_OFF: int
SYNC_NORMAL: int
SYNC_FULL: int

CHECKPOINT_PASSIVE: int
CHECKPOINT_FULL: int
CHECKPOINT_RESTART: int
CHECKPOINT_TRUNCATE: int

OK: int
ERROR: int
BUSY: int
LOCKED: int
NOMEM: int
READONLY: int
CORRUPT: int
NOTFOUND: int
PROTOCOL: int

MAX_COLUMN_FAMILIES: int

# ---------------------------------------------------------------------------
# Exceptions
# ---------------------------------------------------------------------------

class Error(Exception): ...
class NotFoundError(KeyError, Error): ...
class BusyError(Error): ...
class LockedError(Error): ...
class ReadOnlyError(Error): ...
class CorruptError(Error): ...

# ---------------------------------------------------------------------------
# Iterator
# ---------------------------------------------------------------------------

class Iterator:
    def first(self) -> None: ...
    def next(self) -> None: ...
    def eof(self) -> bool: ...
    def key(self) -> bytes: ...
    def value(self) -> bytes: ...
    def item(self) -> Tuple[bytes, bytes]: ...
    def close(self) -> None: ...
    def __iter__(self) -> "Iterator": ...
    def __next__(self) -> Tuple[bytes, bytes]: ...
    def __enter__(self) -> "Iterator": ...
    def __exit__(self, *args: object) -> None: ...

# ---------------------------------------------------------------------------
# ColumnFamily
# ---------------------------------------------------------------------------

class ColumnFamily:
    def put(self, key: bytes, value: bytes) -> None: ...
    def get(self, key: bytes) -> bytes: ...
    def delete(self, key: bytes) -> None: ...
    def exists(self, key: bytes) -> bool: ...
    def iterator(self) -> Iterator: ...
    def prefix_iterator(self, prefix: bytes) -> Iterator: ...
    def close(self) -> None: ...
    def __enter__(self) -> "ColumnFamily": ...
    def __exit__(self, *args: object) -> None: ...

# ---------------------------------------------------------------------------
# KVStore
# ---------------------------------------------------------------------------

class KVStore:
    def __init__(
        self,
        filename: Optional[str] = None,
        journal_mode: int = ...,
    ) -> None: ...

    @classmethod
    def open_v2(
        cls,
        filename: Optional[str] = None,
        journal_mode: int = ...,
        sync_level: int = ...,
        cache_size: int = ...,
        page_size: int = ...,
        read_only: int = ...,
        busy_timeout: int = ...,
        wal_size_limit: int = ...,
    ) -> "KVStore": ...

    def put(self, key: bytes, value: bytes) -> None: ...
    def get(self, key: bytes) -> bytes: ...
    def delete(self, key: bytes) -> None: ...
    def exists(self, key: bytes) -> bool: ...

    def begin(self, write: bool = ...) -> None: ...
    def commit(self) -> None: ...
    def rollback(self) -> None: ...

    def cf_create(self, name: str) -> ColumnFamily: ...
    def cf_open(self, name: str) -> ColumnFamily: ...
    def cf_get_default(self) -> ColumnFamily: ...
    def cf_list(self) -> List[str]: ...
    def cf_drop(self, name: str) -> None: ...

    def iterator(self) -> Iterator: ...
    def prefix_iterator(self, prefix: bytes) -> Iterator: ...

    def errmsg(self) -> str: ...
    def stats(self) -> dict: ...
    def sync(self) -> None: ...
    def vacuum(self, n_pages: int = ...) -> None: ...
    def integrity_check(self) -> None: ...
    def checkpoint(self, mode: int = ...) -> Tuple[int, int]: ...

    def close(self) -> None: ...
    def __enter__(self) -> "KVStore": ...
    def __exit__(self, *args: object) -> None: ...
