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

use super::event_bus::EventBus;

#[derive(Clone, Debug)]
pub enum NetworkEvent {
  SeedConnected(String),
  SeedDisconnected(String),
  AllSeedsConnected,
  BootstrapCompleted,
  NodeReady,
}

static NETWORK_EVENT_BUS: Lazy<Arc<EventBus<NetworkEvent>>> =
  Lazy::new(|| Arc::new(EventBus::new()));

pub fn publish_network_event(event: NetworkEvent) {
  NETWORK_EVENT_BUS.publish(event);
}

pub fn subscribe_network_event() -> broadcast::Receiver<NetworkEvent> {
  NETWORK_EVENT_BUS.subscribe()
}
