2024-04-29 23:34:04 +02:00
|
|
|
use crate::{
|
|
|
|
commander::Commander, events::Events, querier::Querier, shared_engine::SharedEngine,
|
|
|
|
storage::Storage,
|
|
|
|
};
|
|
|
|
|
2024-05-02 23:47:47 +02:00
|
|
|
#[allow(dead_code)]
|
2024-04-29 23:34:04 +02:00
|
|
|
pub struct State {
|
|
|
|
engine: SharedEngine,
|
|
|
|
pub storage: Storage,
|
|
|
|
events: Events,
|
|
|
|
|
|
|
|
pub commander: Commander,
|
|
|
|
pub querier: Querier,
|
|
|
|
}
|
|
|
|
|
2024-05-12 15:54:03 +02:00
|
|
|
pub enum Backend {
|
|
|
|
Local,
|
|
|
|
Remote,
|
|
|
|
}
|
|
|
|
|
2024-04-29 23:34:04 +02:00
|
|
|
impl State {
|
2024-05-12 15:54:03 +02:00
|
|
|
pub async fn new(backend: Backend) -> anyhow::Result<Self> {
|
2024-04-29 23:34:04 +02:00
|
|
|
let storage = Storage::new();
|
|
|
|
let engine = storage.load()?;
|
|
|
|
let events = Events::default();
|
|
|
|
let engine = SharedEngine::from(engine);
|
2024-05-12 21:07:21 +02:00
|
|
|
|
2024-05-12 15:54:03 +02:00
|
|
|
let querier = match backend {
|
|
|
|
Backend::Local => Querier::local(&engine),
|
|
|
|
Backend::Remote => Querier::remote().await?,
|
|
|
|
};
|
2024-04-29 23:34:04 +02:00
|
|
|
|
2024-05-12 21:07:21 +02:00
|
|
|
let commander = match backend {
|
|
|
|
Backend::Local => Commander::local(engine.clone(), storage.clone(), events.clone())?,
|
|
|
|
Backend::Remote => todo!(),
|
|
|
|
};
|
|
|
|
|
2024-04-29 23:34:04 +02:00
|
|
|
Ok(Self {
|
|
|
|
engine: engine.clone(),
|
|
|
|
storage: storage.clone(),
|
|
|
|
events: events.clone(),
|
|
|
|
|
2024-05-12 21:07:21 +02:00
|
|
|
commander,
|
2024-05-12 15:54:03 +02:00
|
|
|
querier,
|
2024-04-29 23:34:04 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|