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

from typing import Callable, Final, TYPE_CHECKING
from typing_extensions import Self
from watchdog import events

"""Declares the EventBasedPathWatcher class, which watches given paths in the file system.

How these classes work together
-------------------------------

- EventBasedPathWatcher : each instance of this is able to watch a single
  file or directory at a given path so long as there's a browser interested in
  it. This uses _MultiPathWatcher to watch paths.

- _MultiPathWatcher : singleton that watches multiple paths. It does this by
  holding a watchdog.observer.Observer object, and manages several
  _FolderEventHandler instances. This creates _FolderEventHandlers as needed,
  if the required folder is not already being watched. And it also tells
  existing _FolderEventHandlers which paths it should be watching for.

- _FolderEventHandler : event handler for when a folder is modified. You can
  register paths in that folder that you're interested in. Then this object
  listens to folder events, sees if registered paths changed, and fires
  callbacks if so.

This module is lazy-loaded and used only if watchdog is installed.
"""
if TYPE_CHECKING:
    ...
_LOGGER: Final = ...
class EventBasedPathWatcher:
    """Watches a single path on disk using watchdog."""
    @staticmethod
    def close_all() -> None:
        """Close the _MultiPathWatcher singleton."""
        ...
    
    def __init__(self, path: str, on_changed: Callable[[str], None], *, glob_pattern: str | None = ..., allow_nonexistent: bool = ...) -> None:
        """Constructor for EventBasedPathWatchers.

        Parameters
        ----------
        path : str
            The path to watch.
        on_changed : Callable[[str], None]
            Callback to call when the path changes.
        glob_pattern : str or None
            A glob pattern to filter the files in a directory that should be
            watched. Only relevant when creating an EventBasedPathWatcher on a
            directory.
        allow_nonexistent : bool
            If True, the watcher will not raise an exception if the path does
            not exist. This can be used to watch for the creation of a file or
            directory at a given path.
        """
        ...
    
    def __repr__(self) -> str:
        ...
    
    def close(self) -> None:
        """Stop watching the path corresponding to this EventBasedPathWatcher."""
        ...
    


class _MultiPathWatcher:
    """Watches multiple paths."""
    _singleton: _MultiPathWatcher | None = ...
    @classmethod
    def get_singleton(cls) -> _MultiPathWatcher:
        """Return the singleton _MultiPathWatcher object.

        Instantiates one if necessary.
        """
        ...
    
    def __new__(cls) -> Self:
        """Constructor."""
        ...
    
    def __init__(self) -> None:
        """Constructor."""
        ...
    
    def __repr__(self) -> str:
        ...
    
    def watch_path(self, path: str, callback: Callable[[str], None], *, glob_pattern: str | None = ..., allow_nonexistent: bool = ...) -> None:
        """Start watching a path."""
        ...
    
    def stop_watching_path(self, path: str, callback: Callable[[str], None]) -> None:
        """Stop watching a path."""
        ...
    
    def close(self) -> None:
        ...
    


class WatchedPath:
    """Emits notifications when a single path is modified."""
    def __init__(self, md5: str, modification_time: float, *, glob_pattern: str | None = ..., allow_nonexistent: bool = ...) -> None:
        ...
    
    def __repr__(self) -> str:
        ...
    


class _FolderEventHandler(events.FileSystemEventHandler):
    """Listen to folder events. If certain paths change, fire a callback.

    The super class, FileSystemEventHandler, listens to changes to *folders*,
    but we need to listen to changes to *both* folders and files. I believe
    this is a limitation of the Mac FSEvents system API, and the watchdog
    library takes the lower common denominator.

    So in this class we watch for folder events and then filter them based
    on whether or not we care for the path the event is about.
    """
    def __init__(self) -> None:
        ...
    
    def __repr__(self) -> str:
        ...
    
    def add_path_change_listener(self, path: str, callback: Callable[[str], None], *, glob_pattern: str | None = ..., allow_nonexistent: bool = ...) -> None:
        """Add a path to this object's event filter."""
        ...
    
    def remove_path_change_listener(self, path: str, callback: Callable[[str], None]) -> None:
        """Remove a path from this object's event filter."""
        ...
    
    def is_watching_paths(self) -> bool:
        """Return true if this object has 1+ paths in its event filter."""
        ...
    
    def handle_path_change_event(self, event: events.FileSystemEvent) -> None:
        """Handle when a path (corresponding to a file or dir) is changed.

        The events that can call this are modification, creation or moved
        events.
        """
        ...
    
    def on_created(self, event: events.FileSystemEvent) -> None:
        ...
    
    def on_modified(self, event: events.FileSystemEvent) -> None:
        ...
    
    def on_moved(self, event: events.FileSystemEvent) -> None:
        ...
    


