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

from enum import Enum
from typing import Final, TYPE_CHECKING
from streamlit.runtime.pages_manager import PagesManager
from streamlit.runtime.scriptrunner.script_cache import ScriptCache
from streamlit.runtime.scriptrunner_utils.script_requests import RerunData
from streamlit.runtime.state import SessionState
from streamlit.runtime.fragment import FragmentStorage
from streamlit.runtime.uploaded_file_manager import UploadedFileManager

if TYPE_CHECKING:
    ...
_LOGGER: Final = ...
class ScriptRunnerEvent(Enum):
    SCRIPT_STARTED = ...
    SCRIPT_STOPPED_WITH_COMPILE_ERROR = ...
    SCRIPT_STOPPED_WITH_SUCCESS = ...
    SCRIPT_STOPPED_FOR_RERUN = ...
    FRAGMENT_STOPPED_WITH_SUCCESS = ...
    SHUTDOWN = ...
    ENQUEUE_FORWARD_MSG = ...


class ScriptRunner:
    def __init__(self, session_id: str, main_script_path: str, session_state: SessionState, uploaded_file_mgr: UploadedFileManager, script_cache: ScriptCache, initial_rerun_data: RerunData, user_info: dict[str, str | bool | None], fragment_storage: FragmentStorage, pages_manager: PagesManager) -> None:
        """Initialize the ScriptRunner.

        (The ScriptRunner won't start executing until start() is called.)

        Parameters
        ----------
        session_id
            The AppSession's id.

        main_script_path
            Path to our main app script.

        session_state
            The AppSession's SessionState instance.

        uploaded_file_mgr
            The File manager to store the data uploaded by the file_uploader widget.

        script_cache
            A ScriptCache instance.

        initial_rerun_data
            RerunData to initialize this ScriptRunner with.

        user_info
            A dict that contains information about the current user. For now,
            it only contains the user's email address.

            {
                "email": "example@example.com"
            }

            Information about the current user is optionally provided when a
            websocket connection is initialized via the "X-Streamlit-User" header.

        fragment_storage
            The AppSession's FragmentStorage instance.
        """
        ...
    
    def __repr__(self) -> str:
        ...
    
    def request_stop(self) -> None:
        """Request that the ScriptRunner stop running its script and
        shut down. The ScriptRunner will handle this request when it reaches
        an interrupt point.

        Safe to call from any thread.
        """
        ...
    
    def request_rerun(self, rerun_data: RerunData) -> bool:
        """Request that the ScriptRunner interrupt its currently-running
        script and restart it.

        If the ScriptRunner has been stopped, this request can't be honored:
        return False.

        Otherwise, record the request and return True. The ScriptRunner will
        handle the rerun request as soon as it reaches an interrupt point.

        Safe to call from any thread.
        """
        ...
    
    def start(self) -> None:
        """Start a new thread to process the ScriptEventQueue.

        This must be called only once.

        """
        ...
    


