from collections.abc import (
    ItemsView as _ItemsView,
)
from collections.abc import (
    Iterator,
    MutableMapping,
    MutableSequence,
)
from collections.abc import (
    KeysView as _KeysView,
)
from collections.abc import (
    ValuesView as _ValuesView,
)
from typing import Any, TypeVar, overload

from typing_extensions import Self, override

_T = TypeVar("_T")

class KeysView(_KeysView[str]):
    def __reversed__(self) -> Iterator[str]: ...
    @override
    def __eq__(self, other: object) -> bool: ...

class ValuesView(_ValuesView[Item]):
    @override
    def __contains__(self, value: object) -> bool: ...
    @override
    def __eq__(self, other: object) -> bool: ...

class ItemsView(_ItemsView[str, Item]):
    @override
    def __contains__(self, item: object) -> bool: ...
    @override
    def __eq__(self, other: object) -> bool: ...

class Document(MutableMapping[str, Any]):
    def __init__(self, data: dict[str, Any] | None = None) -> None: ...
    @staticmethod
    def parse(text: str) -> Document: ...
    @override
    def __iter__(self) -> Iterator[str]: ...
    @override
    def __len__(self) -> int: ...
    def __bool__(self) -> bool: ...
    @override
    def __eq__(self, other: object) -> bool: ...
    @override
    def __getitem__(self, key: str) -> Item: ...
    @override
    def __setitem__(self, key: str, value: Any) -> None: ...
    @override
    def __delitem__(self, key: str) -> None: ...
    @override
    def keys(self) -> KeysView: ...
    @override
    def items(self) -> ItemsView: ...
    @override
    def values(self) -> ValuesView: ...
    @overload
    @override
    def get(self, key: str, /) -> Item | None: ...
    @overload
    def get(self, key: str, default: _T, /) -> Item | _T: ...
    @overload
    @override
    def setdefault(self, key: str, default: None = None, /) -> Item: ...
    @overload
    def setdefault(self, key: str, default: Any, /) -> Item: ...
    def fmt(self) -> None: ...
    def as_toml(self) -> str: ...
    def __copy__(self) -> Document: ...
    def __deepcopy__(self, memo: dict[int, Any] | None = None) -> Document: ...
    @property
    def value(self) -> dict[str, Any]: ...

class Item:
    @staticmethod
    def parse(text: str) -> Item: ...
    def __getattr__(self, name: str) -> Any: ...
    @overload
    def __getitem__(self, key: str | int) -> Item: ...
    @overload
    def __getitem__(self, key: slice) -> list[Item]: ...
    def __setitem__(self, key: str | int | slice, value: Any) -> None: ...
    def __delitem__(self, key: str | int | slice) -> None: ...
    def __len__(self) -> int: ...
    def __iter__(self) -> Iterator[Any]: ...
    def __contains__(self, value: Any) -> bool: ...
    def __bool__(self) -> bool: ...
    @override
    def __eq__(self, other: object) -> bool: ...
    def __iadd__(self, value: Any) -> Self: ...
    # Comparison (scalar-oriented, included on Item for convenience since
    # doc[key] returns Item and narrowing is not always practical)
    def __lt__(self, other: Any) -> bool: ...
    def __le__(self, other: Any) -> bool: ...
    def __gt__(self, other: Any) -> bool: ...
    def __ge__(self, other: Any) -> bool: ...
    # Type conversion
    def __int__(self) -> int: ...
    def __float__(self) -> float: ...
    def __index__(self) -> int: ...
    @override
    def __hash__(self) -> int: ...
    # Arithmetic
    def __add__(self, other: Any) -> Any: ...
    def __radd__(self, other: Any) -> Any: ...
    def __sub__(self, other: Any) -> Any: ...
    def __rsub__(self, other: Any) -> Any: ...
    def __mul__(self, other: Any) -> Any: ...
    def __rmul__(self, other: Any) -> Any: ...
    def __truediv__(self, other: Any) -> Any: ...
    def __rtruediv__(self, other: Any) -> Any: ...
    def __floordiv__(self, other: Any) -> Any: ...
    def __rfloordiv__(self, other: Any) -> Any: ...
    def __mod__(self, other: Any) -> Any: ...
    def __rmod__(self, other: Any) -> Any: ...
    def __pow__(self, other: Any, modulo: Any = None) -> Any: ...
    def __rpow__(self, other: Any, modulo: Any = None) -> Any: ...
    def __neg__(self) -> Any: ...
    def __pos__(self) -> Any: ...
    def __abs__(self) -> Any: ...
    def __invert__(self) -> Any: ...
    @override
    def __format__(self, spec: str) -> str: ...
    @property
    def value(self) -> Any: ...
    @property
    def comment(self) -> str | None: ...
    @comment.setter
    def comment(self, value: str | None) -> None: ...
    @property
    def inline_comment(self) -> str | None: ...
    @inline_comment.setter
    def inline_comment(self, value: str | None) -> None: ...
    def clear(self) -> None: ...
    def fmt(self) -> None: ...
    def as_toml(self) -> str: ...

class DictItem(Item, MutableMapping[str, Any]):
    @staticmethod
    @override
    def parse(text: str) -> DictItem: ...
    @override
    def __iter__(self) -> Iterator[str]: ...
    @override
    def keys(self) -> KeysView: ...
    @override
    def values(self) -> ValuesView: ...
    @override
    def items(self) -> ItemsView: ...
    @overload
    @override
    def get(self, key: str, /) -> Item | None: ...
    @overload
    def get(self, key: str, default: _T, /) -> Item | _T: ...
    @override
    def setdefault(self, key: str, default: Any = ..., /) -> Item: ...

class ListItem(Item, MutableSequence[Any]):
    @staticmethod
    @override
    def parse(text: str) -> ListItem: ...
    @override
    def insert(self, index: int, value: Any, /) -> None: ...
    def set_multiline(self, *, indent: int = 4) -> None: ...

class ScalarItem(Item):
    @staticmethod
    @override
    def parse(text: str) -> ScalarItem: ...
