use crate::event_bus::{EventBusConfig, ResourceEvent}; use reddwarf_storage::RedbBackend; use reddwarf_versioning::VersionStore; use std::sync::Arc; use tokio::sync::broadcast; /// Shared application state #[derive(Clone)] pub struct AppState { /// Storage backend pub storage: Arc, /// Version store pub version_store: Arc, /// Event bus sender — broadcast channel for resource mutation events pub event_tx: broadcast::Sender, } impl AppState { /// Create a new AppState with default event bus config pub fn new(storage: Arc, version_store: Arc) -> Self { Self::with_event_bus_config(storage, version_store, EventBusConfig::default()) } /// Create a new AppState with custom event bus config pub fn with_event_bus_config( storage: Arc, version_store: Arc, config: EventBusConfig, ) -> Self { let (event_tx, _) = broadcast::channel(config.capacity); Self { storage, version_store, event_tx, } } /// Subscribe to resource events pub fn subscribe(&self) -> broadcast::Receiver { self.event_tx.subscribe() } }