use origin_accounts::AccountService;
use origin_connector::ConnectorRegistry;
use origin_domain::{AppError, Clock, Result};
use origin_events::EventBus;
use origin_http::HttpClient;
use origin_jobs::Jobs;
use origin_platform::{NotificationService, Opener};
use origin_secrets::SecretStore;
use origin_settings::Settings;
use origin_storage::{Cache, Storage};
use origin_sync::SyncEngine;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct Platform {
pub clock: Arc<dyn Clock>,
pub events: EventBus,
pub storage: Arc<dyn Storage>,
pub cache: Cache,
pub secrets: Arc<dyn SecretStore>,
pub settings: Settings,
pub notifications: Arc<dyn NotificationService>,
pub jobs: Jobs,
pub sync: SyncEngine,
pub accounts: AccountService,
pub connectors: ConnectorRegistry,
pub opener: Option<Arc<dyn Opener>>,
pub http: Option<Arc<dyn HttpClient>>,
}
impl Platform {
pub fn http(&self) -> Result<Arc<dyn HttpClient>> {
self.http.clone().ok_or_else(|| {
AppError::configuration(
"this application has no http client — add `.http_client(...)` to its \
composition root",
)
})
}
pub fn opener(&self) -> Result<Arc<dyn Opener>> {
self.opener.clone().ok_or_else(|| {
AppError::Permission("this application cannot open external urls".to_owned())
})
}
}