from types import ModuleType

from app.services.payments import chapa

# One entry per gateway module this codebase actually integrates
# with directly (see app.services.payments.base.PaymentProvider for
# what each one has to expose) — add telebirr/cbe/coopay here once
# each has real API access to build against; nothing else needs to
# change to add one, since every caller already goes through
# get_provider/list_available_providers rather than importing a
# specific gateway module itself.
_PROVIDERS: dict[str, ModuleType] = {
    chapa.PROVIDER_NAME: chapa,
}


def get_provider(name: str) -> ModuleType:
    try:
        return _PROVIDERS[name]
    except KeyError:
        raise ValueError(f"Unknown payment provider: {name!r}") from None


def list_available_providers() -> list[str]:
    """Only the ones with real credentials configured right now — same
    reasoning as every other opt-in-when-configured integration in
    this codebase (see app.core.config)."""
    return [name for name, provider in _PROVIDERS.items() if provider.is_configured()]
