use crate::module::ModuleRegistry;
use crate::platform::Platform;
use origin_domain::Result;
use serde::Serialize;
use std::sync::Arc;
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "ts", derive(ts_rs::TS))]
pub struct AppInfo {
pub id: String,
pub name: String,
pub version: String,
pub modules: Vec<String>,
}
#[derive(Debug)]
pub struct Application {
platform: Platform,
registry: ModuleRegistry,
}
impl Application {
pub(crate) fn new(platform: Platform, registry: ModuleRegistry) -> Self {
Self { platform, registry }
}
pub fn platform(&self) -> &Platform {
&self.platform
}
pub fn service<T: Send + Sync + 'static>(&self) -> Option<Arc<T>> {
self.registry.service::<T>()
}
pub fn require<T: Send + Sync + 'static>(&self) -> Result<Arc<T>> {
self.registry.require::<T>()
}
pub fn modules(&self) -> &[&'static str] {
self.registry.module_ids()
}
}