use crate::api::MmexContext;
use crate::ffi::accounts::AccountManager;
use crate::ffi::assets::AssetManager;
use crate::ffi::categories::CategoryManager;
use crate::ffi::currencies::CurrencyManager;
use crate::ffi::payees::PayeeManager;
use crate::ffi::scheduled::ScheduledManager;
use crate::ffi::stocks::StockManager;
use crate::ffi::support::SupportManager;
use crate::ffi::tags::TagManager;
use crate::ffi::transactions::TransactionManager;
use crate::MmexError;
use std::sync::{Arc, Mutex};
#[derive(uniffi::Object)]
pub struct MmexEngine {
pub(crate) context: Arc<Mutex<MmexContext>>,
}
#[uniffi::export]
impl MmexEngine {
#[uniffi::constructor]
pub fn new(path: String, key: Option<String>) -> Result<Arc<Self>, MmexError> {
let ctx = MmexContext::open((&path).as_ref(), key)?;
Ok(Arc::new(Self {
context: Arc::new(Mutex::new(ctx)),
}))
}
pub fn tags(&self) -> Arc<TagManager> {
Arc::new(TagManager {
context: self.context.clone(),
})
}
pub fn accounts(&self) -> Arc<AccountManager> {
Arc::new(AccountManager {
context: self.context.clone(),
})
}
pub fn payees(&self) -> Arc<PayeeManager> {
Arc::new(PayeeManager {
context: self.context.clone(),
})
}
pub fn currencies(&self) -> Arc<CurrencyManager> {
Arc::new(CurrencyManager {
context: self.context.clone(),
})
}
pub fn categories(&self) -> Arc<CategoryManager> {
Arc::new(CategoryManager {
context: self.context.clone(),
})
}
pub fn transactions(&self) -> Arc<TransactionManager> {
Arc::new(TransactionManager {
context: self.context.clone(),
})
}
pub fn scheduled(&self) -> Arc<ScheduledManager> {
Arc::new(ScheduledManager {
context: self.context.clone(),
})
}
pub fn assets(&self) -> Arc<AssetManager> {
Arc::new(AssetManager {
context: self.context.clone(),
})
}
pub fn stocks(&self) -> Arc<StockManager> {
Arc::new(StockManager {
context: self.context.clone(),
})
}
pub fn support(&self) -> Arc<SupportManager> {
Arc::new(SupportManager {
context: self.context.clone(),
})
}
}