from collections.abc import Awaitable, Callable
from threading import Lock

ProgressCallback = Callable[[str, str, str, dict | None], Awaitable[None] | None]


class ProgressRegistry:
    def __init__(self) -> None:
        self._items: dict[str, ProgressCallback] = {}
        self._lock = Lock()

    def register(self, key: str, callback: ProgressCallback) -> None:
        with self._lock:
            self._items[key] = callback

    def get(self, key: str | None) -> ProgressCallback | None:
        if not key:
            return None
        with self._lock:
            return self._items.get(key)

    def unregister(self, key: str) -> None:
        with self._lock:
            self._items.pop(key, None)


progress_registry = ProgressRegistry()
