"""Registry of academic data sources used by the journal-quality system.

Each source is a `DataSource` subclass that declares its metadata and
implements `fetch()`. To add a new dataset (institutions, conferences,
…), drop in a new module containing one subclass and append an instance
to `ALL_SOURCES` below. The bulk downloader, status endpoint, dashboard
banner, and lazy-load auto-download path will all pick it up
automatically.
"""

from __future__ import annotations

from .base import DataSource
from .doaj import DOAJSource
from .institutions import InstitutionSource
from .jabref import JabRefSource
from .openalex import OpenAlexSource
from .predatory import PredatorySource

# Order matters for the bulk download flow:
#   1. OpenAlex first (required=True; failure aborts the batch)
#   2. DOAJ, predatory, jabref, institutions are best-effort and can
#      fail independently
ALL_SOURCES: list[DataSource] = [
    OpenAlexSource(),
    DOAJSource(),
    PredatorySource(),
    JabRefSource(),
    InstitutionSource(),
]


def get_source(key: str) -> DataSource:
    """Look up a data source by its `key` attribute.

    Raises:
        KeyError: if no source with that key is registered.
    """
    for src in ALL_SOURCES:
        if src.key == key:
            return src
    raise KeyError(f"Unknown data source: {key!r}")


__all__ = ["DataSource", "ALL_SOURCES", "get_source"]
