use std::path::PathBuf;
use std::sync::Arc;
use astrid_core::principal::PrincipalId;
use astrid_events::EventBus;
use astrid_storage::ScopedKvStore;
use astrid_core::session_token::SessionToken;
use crate::registry::CapsuleRegistry;
pub struct CapsuleContext {
pub principal: PrincipalId,
pub workspace_root: PathBuf,
pub home_root: Option<PathBuf>,
pub kv: ScopedKvStore,
pub event_bus: Arc<EventBus>,
pub cli_socket_listener: Option<Arc<tokio::sync::Mutex<tokio::net::UnixListener>>>,
pub capsule_registry: Option<Arc<tokio::sync::RwLock<CapsuleRegistry>>>,
pub session_token: Option<Arc<SessionToken>>,
pub allowance_store: Option<Arc<astrid_approval::AllowanceStore>>,
pub identity_store: Option<Arc<dyn astrid_storage::IdentityStore>>,
}
impl CapsuleContext {
#[must_use]
pub fn new(
principal: PrincipalId,
workspace_root: PathBuf,
home_root: Option<PathBuf>,
kv: ScopedKvStore,
event_bus: Arc<EventBus>,
cli_socket_listener: Option<Arc<tokio::sync::Mutex<tokio::net::UnixListener>>>,
) -> Self {
Self {
principal,
workspace_root,
home_root,
kv,
event_bus,
cli_socket_listener,
capsule_registry: None,
session_token: None,
allowance_store: None,
identity_store: None,
}
}
#[must_use]
pub fn with_session_token(mut self, token: Arc<SessionToken>) -> Self {
self.session_token = Some(token);
self
}
#[must_use]
pub fn with_registry(mut self, registry: Arc<tokio::sync::RwLock<CapsuleRegistry>>) -> Self {
self.capsule_registry = Some(registry);
self
}
#[must_use]
pub fn with_allowance_store(mut self, store: Arc<astrid_approval::AllowanceStore>) -> Self {
self.allowance_store = Some(store);
self
}
#[must_use]
pub fn with_identity_store(mut self, store: Arc<dyn astrid_storage::IdentityStore>) -> Self {
self.identity_store = Some(store);
self
}
}