"""Shared helper for firing in-app notifications from other apps.

Usage:
    from apps.notifications.utils import notify

    notify(user, title="...", message="...", notification_type="procurement", icon="shopping-cart")
"""


def notify(user, *, title, message, notification_type, icon, link="", priority="medium", related_user=None):
    """Fire an in-app notification; never break the caller's request on failure."""
    if not user:
        return
    try:
        from apps.notifications.handler import NotificationHandler
        NotificationHandler.send(
            user=user, title=title, message=message,
            notification_type=notification_type, priority=priority, icon=icon,
            link=link, related_user=related_user, broadcast=True,
        )
    except Exception:
        pass
