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

import contextlib
import contextvars
import threading
from collections import Counter
from dataclasses import dataclass
from typing import Callable, Final, TYPE_CHECKING, Union
from typing_extensions import TypeAlias
from pathlib import Path
from streamlit.cursor import RunningCursor
from streamlit.proto.ClientState_pb2 import ContextInfo
from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
from streamlit.proto.PageProfile_pb2 import Command
from streamlit.runtime.fragment import FragmentStorage
from streamlit.runtime.pages_manager import PagesManager
from streamlit.runtime.scriptrunner_utils.script_requests import ScriptRequests
from streamlit.runtime.state import SafeSessionState
from streamlit.runtime.uploaded_file_manager import UploadedFileManager

if TYPE_CHECKING:
    ...
_LOGGER: Final = ...
UserInfo: TypeAlias = dict[str, Union[str, bool, None]]
in_cached_function: contextvars.ContextVar[bool] = ...
@dataclass
class ScriptRunContext:
    """A context object that contains data for a "script run" - that is,
    data that's scoped to a single ScriptRunner execution (and therefore also
    scoped to a single connected "session").

    ScriptRunContext is used internally by virtually every `st.foo()` function.
    It is accessed only from the script thread that's created by ScriptRunner,
    or from app-created helper threads that have been "attached" to the
    ScriptRunContext via `add_script_run_ctx`.

    Streamlit code typically retrieves the active ScriptRunContext via the
    `get_script_run_ctx` function.
    """
    session_id: str
    _enqueue: Callable[[ForwardMsg], None]
    query_string: str
    session_state: SafeSessionState
    uploaded_file_mgr: UploadedFileManager
    main_script_path: str
    user_info: UserInfo
    fragment_storage: FragmentStorage
    pages_manager: PagesManager
    cached_message_hashes: set[str] = ...
    context_info: ContextInfo | None = ...
    gather_usage_stats: bool = ...
    command_tracking_deactivated: bool = ...
    tracked_commands: list[Command] = ...
    tracked_commands_counter: Counter[str] = ...
    _set_page_config_allowed: bool = ...
    _has_script_started: bool = ...
    widget_ids_this_run: set[str] = ...
    widget_user_keys_this_run: set[str] = ...
    form_ids_this_run: set[str] = ...
    cursors: dict[int, RunningCursor] = ...
    script_requests: ScriptRequests | None = ...
    current_fragment_id: str | None = ...
    fragment_ids_this_run: list[str] | None = ...
    new_fragment_ids: set[str] = ...
    _active_script_hash: str = ...
    has_dialog_opened: bool = ...
    _experimental_query_params_used = ...
    _production_query_params_used = ...
    @property
    def page_script_hash(self): # -> PageHash:
        ...
    
    @property
    def active_script_hash(self): # -> str:
        ...
    
    @property
    def main_script_parent(self) -> Path:
        ...
    
    @contextlib.contextmanager
    def run_with_active_hash(self, page_hash: str): # -> Generator[None, Any, None]:
        ...
    
    def set_mpa_v2_page(self, page_script_hash: str): # -> None:
        ...
    
    def reset(self, query_string: str = ..., page_script_hash: str = ..., fragment_ids_this_run: list[str] | None = ..., cached_message_hashes: set[str] | None = ..., context_info: ContextInfo | None = ...) -> None:
        ...
    
    def on_script_start(self) -> None:
        ...
    
    def enqueue(self, msg: ForwardMsg) -> None:
        """Enqueue a ForwardMsg for this context's session."""
        ...
    
    def ensure_single_query_api_used(self): # -> None:
        ...
    
    def mark_experimental_query_params_used(self): # -> None:
        ...
    
    def mark_production_query_params_used(self): # -> None:
        ...
    


SCRIPT_RUN_CONTEXT_ATTR_NAME: Final = ...
def add_script_run_ctx(thread: threading.Thread | None = ..., ctx: ScriptRunContext | None = ...): # -> Thread:
    """Adds the current ScriptRunContext to a newly-created thread.

    This should be called from this thread's parent thread,
    before the new thread starts.

    Parameters
    ----------
    thread : threading.Thread
        The thread to attach the current ScriptRunContext to.
    ctx : ScriptRunContext or None
        The ScriptRunContext to add, or None to use the current thread's
        ScriptRunContext.

    Returns
    -------
    threading.Thread
        The same thread that was passed in, for chaining.

    """
    ...

def get_script_run_ctx(suppress_warning: bool = ...) -> ScriptRunContext | None:
    """
    Parameters
    ----------
    suppress_warning : bool
        If True, don't log a warning if there's no ScriptRunContext.

    Returns
    -------
    ScriptRunContext | None
        The current thread's ScriptRunContext, or None if it doesn't have one.

    """
    ...

def enqueue_message(msg: ForwardMsg) -> None:
    """Enqueues a ForwardMsg proto to send to the app."""
    ...

