"""DMS notification dispatch helper.

``dispatch_dms_notification`` is a thin, best-effort wrapper around the
platform notification service.  Handlers call this function; failures are
logged but never propagated so that a broken notification path can never
interrupt the core DMS workflow.
"""

from __future__ import annotations

import structlog
from collections.abc import Iterable
from typing import Any

_log = structlog.get_logger("simorgh.dms.notifications")


def dispatch_dms_notification(
    kind: str,
    *,
    recipients: Iterable[Any],
    context: dict[str, Any],
    tenant_id: int,
    organization_node_id: int,
) -> None:
    """Fire a DMS notification.  Never raises — failures are logged only."""
    try:
        from simorgh.apps.notifications.services import dispatch as _dispatch

        _dispatch(
            kind,
            recipients=list(recipients),
            context=context,
            tenant_id=tenant_id,
            organization_node_id=organization_node_id,
        )
    except Exception:
        _log.warning(
            "dms.notifications.dispatch_failed",
            kind=kind,
            exc_info=True,
        )
