from _typeshed import MaybeNone, SupportsItems, SupportsKeysAndGetItem
from collections.abc import Container, Iterable
from types import GenericAlias
from typing import Any, Generic, TypeVar, overload

__all__ = ["CookieError", "BaseCookie", "SimpleCookie"]

_T = TypeVar("_T")

@overload
def _quote(str: None) -> None: ...
@overload
def _quote(str: str) -> str: ...

@overload
def _unquote(str: None) -> None: ...
@overload
def _unquote(str: str) -> str: ...

class CookieError(Exception): ...

class Morsel(dict[str, Any], Generic[_T]):
    @property
    def value(self) -> str | MaybeNone: ...
    @property
    def coded_value(self) -> _T | MaybeNone: ...
    @property
    def key(self) -> str | MaybeNone: ...
    def __init__(self) -> None: ...
    def set(self, key: str, val: str, coded_val: _T) -> None: ...
    def setdefault(self, key: str, val: str | None = None) -> str: ...
    # The dict update can also get a keywords argument so this is incompatible
    def update(self, values: Iterable[tuple[str, str]] | SupportsKeysAndGetItem[str, str]) -> None: ...  # type: ignore[override]
    def isReservedKey(self, K: str) -> bool: ...
    def output(self, attrs: Container[str] | None = None, header: str = "Set-Cookie:") -> str: ...
    __str__ = output
    def js_output(self, attrs: Container[str] | None = None) -> str: ...
    def OutputString(self, attrs: Container[str] | None = None) -> str: ...
    def __eq__(self, morsel: object) -> bool: ...
    def __setitem__(self, K: str, V: Any) -> None: ...
    def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

class BaseCookie(dict[str, Morsel[_T]], Generic[_T]):
    def __init__(self, input: str | SupportsItems[str, str | Morsel[Any]] | None = None) -> None: ...
    def value_decode(self, val: str) -> tuple[_T, str]: ...
    def value_encode(self, val: _T) -> tuple[str, str]: ...
    def output(self, attrs: Container[str] | None = None, header: str = "Set-Cookie:", sep: str = "\r\n") -> str: ...
    __str__ = output
    def js_output(self, attrs: Container[str] | None = None) -> str: ...
    def load(self, rawdata: str | SupportsItems[str, str | Morsel[Any]]) -> None: ...
    def __setitem__(self, key: str, value: str | Morsel[_T]) -> None: ...

class SimpleCookie(BaseCookie[str]): ...
