use std::sync::Arc;
use crate::application::service::BankService;
use crate::application::service::BankAccountService;
use crate::application::service::BankClearanceService;
use crate::application::service::BankReconciliationService;
use crate::application::service::BankStatementImportService;
use crate::application::service::BankTransactionService;
use crate::application::service::FxGainLossService;
use crate::application::service::ReconcilePresetService;
#[derive(Clone)]
pub struct AppState {
pub bank_service: Arc<BankService>,
pub bank_account_service: Arc<BankAccountService>,
pub bank_clearance_service: Arc<BankClearanceService>,
pub bank_reconciliation_service: Arc<BankReconciliationService>,
pub bank_statement_import_service: Arc<BankStatementImportService>,
pub bank_transaction_service: Arc<BankTransactionService>,
pub fx_gain_loss_service: Arc<FxGainLossService>,
pub reconcile_preset_service: Arc<ReconcilePresetService>,
}
impl AppState {
pub fn new(
bank_service: Arc<BankService>,
bank_account_service: Arc<BankAccountService>,
bank_clearance_service: Arc<BankClearanceService>,
bank_reconciliation_service: Arc<BankReconciliationService>,
bank_statement_import_service: Arc<BankStatementImportService>,
bank_transaction_service: Arc<BankTransactionService>,
fx_gain_loss_service: Arc<FxGainLossService>,
reconcile_preset_service: Arc<ReconcilePresetService>
) -> Self {
Self {
bank_service,
bank_account_service,
bank_clearance_service,
bank_reconciliation_service,
bank_statement_import_service,
bank_transaction_service,
fx_gain_loss_service,
reconcile_preset_service,
}
}
pub fn from_module(module: &crate::BankingModule) -> Self {
Self {
bank_service: module.bank_service.clone(),
bank_account_service: module.bank_account_service.clone(),
bank_clearance_service: module.bank_clearance_service.clone(),
bank_reconciliation_service: module.bank_reconciliation_service.clone(),
bank_statement_import_service: module.bank_statement_import_service.clone(),
bank_transaction_service: module.bank_transaction_service.clone(),
fx_gain_loss_service: module.fx_gain_loss_service.clone(),
reconcile_preset_service: module.reconcile_preset_service.clone(),
}
}
}
#[derive(Default)]
pub struct AppStateBuilder {
bank_service: Option<Arc<BankService>>,
bank_account_service: Option<Arc<BankAccountService>>,
bank_clearance_service: Option<Arc<BankClearanceService>>,
bank_reconciliation_service: Option<Arc<BankReconciliationService>>,
bank_statement_import_service: Option<Arc<BankStatementImportService>>,
bank_transaction_service: Option<Arc<BankTransactionService>>,
fx_gain_loss_service: Option<Arc<FxGainLossService>>,
reconcile_preset_service: Option<Arc<ReconcilePresetService>>,
}
impl AppStateBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn with_bank_service(mut self, service: Arc<BankService>) -> Self {
self.bank_service = Some(service);
self
}
pub fn with_bank_account_service(mut self, service: Arc<BankAccountService>) -> Self {
self.bank_account_service = Some(service);
self
}
pub fn with_bank_clearance_service(mut self, service: Arc<BankClearanceService>) -> Self {
self.bank_clearance_service = Some(service);
self
}
pub fn with_bank_reconciliation_service(mut self, service: Arc<BankReconciliationService>) -> Self {
self.bank_reconciliation_service = Some(service);
self
}
pub fn with_bank_statement_import_service(mut self, service: Arc<BankStatementImportService>) -> Self {
self.bank_statement_import_service = Some(service);
self
}
pub fn with_bank_transaction_service(mut self, service: Arc<BankTransactionService>) -> Self {
self.bank_transaction_service = Some(service);
self
}
pub fn with_fx_gain_loss_service(mut self, service: Arc<FxGainLossService>) -> Self {
self.fx_gain_loss_service = Some(service);
self
}
pub fn with_reconcile_preset_service(mut self, service: Arc<ReconcilePresetService>) -> Self {
self.reconcile_preset_service = Some(service);
self
}
pub fn build(self) -> AppState {
AppState {
bank_service: self.bank_service.expect("bank_service is required"),
bank_account_service: self.bank_account_service.expect("bank_account_service is required"),
bank_clearance_service: self.bank_clearance_service.expect("bank_clearance_service is required"),
bank_reconciliation_service: self.bank_reconciliation_service.expect("bank_reconciliation_service is required"),
bank_statement_import_service: self.bank_statement_import_service.expect("bank_statement_import_service is required"),
bank_transaction_service: self.bank_transaction_service.expect("bank_transaction_service is required"),
fx_gain_loss_service: self.fx_gain_loss_service.expect("fx_gain_loss_service is required"),
reconcile_preset_service: self.reconcile_preset_service.expect("reconcile_preset_service is required"),
}
}
}