"""Sink registry — name/URI → sink instance factory."""

from __future__ import annotations

from typing import Any

from .base import BaseSink

# name → factory callable
_registry: dict[str, type[BaseSink]] = {}


def register_sink(name: str, sink_class: type[BaseSink]) -> None:
    _registry[name] = sink_class


def get_sink(name: str, **kwargs: Any) -> BaseSink:
    """Instantiate a registered sink by name with kwargs."""
    if name not in _registry:
        names = sorted(_registry.keys())
        raise ImportError(
            f"No sink registered for {name!r}. Available: {names}. "
            f"Check that the required extra is installed."
        )
    return _registry[name](**kwargs)


def list_sinks() -> list[str]:
    return sorted(_registry.keys())
