# app/src/runtime_events/publisher.py

from __future__ import annotations

import asyncio

from src.runtime_events.models import RuntimeEvent


class RuntimeEventPublisher:
    @classmethod
    def publish(cls, event: RuntimeEvent) -> None:
        try:
            loop = asyncio.get_running_loop()
        except RuntimeError:
            return

        # lazy import, чтобы не ловить circular import:
        # runtime_events -> notifications -> runtime_events
        from src.notifications.service import NotificationService

        loop.create_task(NotificationService().handle_runtime_event(event))