use once_cell::sync::Lazy;
use std::sync::Arc;
use tokio::sync::broadcast;

use super::event_bus::EventBus;

#[derive(Clone, Debug)]
pub enum SystemEvent {
  ExecutorStarted,
  RendererStarted,
  NodeStarted,
  Shutdown,
  Abort,
}

static SYSTEM_EVENT_BUS: Lazy<Arc<EventBus<SystemEvent>>> = Lazy::new(|| Arc::new(EventBus::new()));

pub fn publish_system_event(event: SystemEvent) {
  SYSTEM_EVENT_BUS.publish(event);
}

pub fn subscribe_system_event() -> broadcast::Receiver<SystemEvent> {
  SYSTEM_EVENT_BUS.subscribe()
}
