"""Configuration validation never instantiates a transport or exposes values."""
from django.core.checks import Error, register
from .providers import get_provider
from django.conf import settings


@register()
def communication_configuration(app_configs, **kwargs):
    errors = []
    for channel in ("SMS", "EMAIL"):
        path = getattr(settings, "COMMUNICATION_PROVIDERS", {}).get(channel)
        if not path:
            continue
        try:
            get_provider(channel)
        except Exception:
            errors.append(Error(f"Invalid or unsafe {channel} provider configuration; review deployment settings.", id="communications.E002"))
    return errors
