"""
This type stub file was generated by pyright.
"""

import types
from typing import Any, Callable, Final, TYPE_CHECKING, TypeVar, overload
from typing_extensions import TypeAlias
from streamlit.runtime.caching.cache_type import CacheType
from streamlit.runtime.caching.cache_utils import Cache, CachedFuncInfo
from streamlit.runtime.caching.cached_message_replay import CachedMessageReplayContext, CachedResult, MsgData
from streamlit.runtime.metrics_util import gather_metrics
from streamlit.runtime.stats import CacheStat, CacheStatsProvider
from datetime import timedelta
from streamlit.runtime.caching.hashing import HashFuncsDict

"""@st.cache_resource implementation."""
if TYPE_CHECKING:
    ...
_LOGGER: Final = ...
CACHE_RESOURCE_MESSAGE_REPLAY_CTX = ...
ValidateFunc: TypeAlias = Callable[[Any], bool]
class ResourceCaches(CacheStatsProvider):
    """Manages all ResourceCache instances."""
    def __init__(self) -> None:
        ...
    
    def get_cache(self, key: str, display_name: str, max_entries: int | float | None, ttl: float | timedelta | str | None, validate: ValidateFunc | None) -> ResourceCache:
        """Return the mem cache for the given key.

        If it doesn't exist, create a new one with the given params.
        """
        ...
    
    def clear_all(self) -> None:
        """Clear all resource caches."""
        ...
    
    def get_stats(self) -> list[CacheStat]:
        ...
    


_resource_caches = ...
def get_resource_cache_stats_provider() -> CacheStatsProvider:
    """Return the StatsProvider for all @st.cache_resource functions."""
    ...

class CachedResourceFuncInfo(CachedFuncInfo):
    """Implements the CachedFuncInfo interface for @st.cache_resource."""
    def __init__(self, func: types.FunctionType, show_spinner: bool | str, max_entries: int | None, ttl: float | timedelta | str | None, validate: ValidateFunc | None, hash_funcs: HashFuncsDict | None = ...) -> None:
        ...
    
    @property
    def cache_type(self) -> CacheType:
        ...
    
    @property
    def cached_message_replay_ctx(self) -> CachedMessageReplayContext:
        ...
    
    @property
    def display_name(self) -> str:
        """A human-readable name for the cached function."""
        ...
    
    def get_function_cache(self, function_key: str) -> Cache:
        ...
    


class CacheResourceAPI:
    """Implements the public st.cache_resource API: the @st.cache_resource decorator,
    and st.cache_resource.clear().
    """
    def __init__(self, decorator_metric_name: str) -> None:
        """Create a CacheResourceAPI instance.

        Parameters
        ----------
        decorator_metric_name
            The metric name to record for decorator usage.
        """
        ...
    
    F = TypeVar("F", bound=Callable[..., Any])
    @overload
    def __call__(self, func: F) -> F:
        ...
    
    @overload
    def __call__(self, *, ttl: float | timedelta | str | None = ..., max_entries: int | None = ..., show_spinner: bool | str = ..., validate: ValidateFunc | None = ..., experimental_allow_widgets: bool = ..., hash_funcs: HashFuncsDict | None = ...) -> Callable[[F], F]:
        ...
    
    def __call__(self, func: F | None = ..., *, ttl: float | timedelta | str | None = ..., max_entries: int | None = ..., show_spinner: bool | str = ..., validate: ValidateFunc | None = ..., experimental_allow_widgets: bool = ..., hash_funcs: HashFuncsDict | None = ...): # -> Callable[..., Callable[..., Any]] | Callable[..., Any]:
        ...
    
    @gather_metrics("clear_resource_caches")
    def clear(self) -> None:
        """Clear all cache_resource caches."""
        ...
    


class ResourceCache(Cache):
    """Manages cached values for a single st.cache_resource function."""
    def __init__(self, key: str, max_entries: float, ttl_seconds: float, validate: ValidateFunc | None, display_name: str) -> None:
        ...
    
    @property
    def max_entries(self) -> float:
        ...
    
    @property
    def ttl_seconds(self) -> float:
        ...
    
    def read_result(self, key: str) -> CachedResult:
        """Read a value and associated messages from the cache.
        Raise `CacheKeyNotFoundError` if the value doesn't exist.
        """
        ...
    
    @gather_metrics("_cache_resource_object")
    def write_result(self, key: str, value: Any, messages: list[MsgData]) -> None:
        """Write a value and associated messages to the cache."""
        ...
    
    def get_stats(self) -> list[CacheStat]:
        ...
    


