"""Source connector registry — scheme -> connector instance."""

from __future__ import annotations

from .base import BaseSource

_registry: dict[str, BaseSource] = {}


def register_source(connector: BaseSource) -> None:
    _registry[connector.scheme] = connector


def get_source(scheme: str) -> BaseSource:
    if scheme not in _registry:
        _hint = _install_hint(scheme)
        raise ImportError(f"No source connector registered for scheme {scheme!r}. {_hint}")
    return _registry[scheme]


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


def _install_hint(scheme: str) -> str:
    hints = {
        "s3": "Run: pip install 'coresdk-extractor[s3]'",
        "minio": "Run: pip install 'coresdk-extractor[s3]'",
        "az": "Run: pip install 'coresdk-extractor[azure]'",
        "abfs": "Run: pip install 'coresdk-extractor[azure]'",
        "gcs": "Run: pip install 'coresdk-extractor[gcs]'",
        "gs": "Run: pip install 'coresdk-extractor[gcs]'",
        "http": "HTTP source is built-in (no extra needed)",
        "https": "HTTPS source is built-in (no extra needed)",
        "email": "Run: pip install 'coresdk-extractor[email]'",
        "imap": "Run: pip install 'coresdk-extractor[email]'",
        "imaps": "Run: pip install 'coresdk-extractor[email]'",
        "sftp": "Run: pip install 'coresdk-extractor[sftp]'",
    }
    return hints.get(scheme, "Install the appropriate connector extra.")
