use std::sync::Arc;
use crate::application::service::PosClosingEntryService;
use crate::application::service::PosInvoiceService;
use crate::application::service::PosInvoiceItemService;
use crate::application::service::PosPaymentService;
use crate::application::service::PosProfileService;
use crate::application::service::PosOpeningEntryService;
use crate::application::service::PosCashMovementService;
use crate::application::service::PosDiscountService;
use crate::application::service::PosManagerPinService;
use crate::application::service::PosFloorPlanService;
use crate::application::service::PosTableService;
#[derive(Clone)]
pub struct AppState {
pub pos_closing_entry_service: Arc<PosClosingEntryService>,
pub pos_invoice_service: Arc<PosInvoiceService>,
pub pos_invoice_item_service: Arc<PosInvoiceItemService>,
pub pos_payment_service: Arc<PosPaymentService>,
pub pos_profile_service: Arc<PosProfileService>,
pub pos_opening_entry_service: Arc<PosOpeningEntryService>,
pub pos_cash_movement_service: Arc<PosCashMovementService>,
pub pos_discount_service: Arc<PosDiscountService>,
pub pos_manager_pin_service: Arc<PosManagerPinService>,
pub pos_floor_plan_service: Arc<PosFloorPlanService>,
pub pos_table_service: Arc<PosTableService>,
}
impl AppState {
pub fn new(
pos_closing_entry_service: Arc<PosClosingEntryService>,
pos_invoice_service: Arc<PosInvoiceService>,
pos_invoice_item_service: Arc<PosInvoiceItemService>,
pos_payment_service: Arc<PosPaymentService>,
pos_profile_service: Arc<PosProfileService>,
pos_opening_entry_service: Arc<PosOpeningEntryService>,
pos_cash_movement_service: Arc<PosCashMovementService>,
pos_discount_service: Arc<PosDiscountService>,
pos_manager_pin_service: Arc<PosManagerPinService>,
pos_floor_plan_service: Arc<PosFloorPlanService>,
pos_table_service: Arc<PosTableService>
) -> Self {
Self {
pos_closing_entry_service,
pos_invoice_service,
pos_invoice_item_service,
pos_payment_service,
pos_profile_service,
pos_opening_entry_service,
pos_cash_movement_service,
pos_discount_service,
pos_manager_pin_service,
pos_floor_plan_service,
pos_table_service,
}
}
pub fn from_module(module: &crate::PosModule) -> Self {
Self {
pos_closing_entry_service: module.pos_closing_entry_service.clone(),
pos_invoice_service: module.pos_invoice_service.clone(),
pos_invoice_item_service: module.pos_invoice_item_service.clone(),
pos_payment_service: module.pos_payment_service.clone(),
pos_profile_service: module.pos_profile_service.clone(),
pos_opening_entry_service: module.pos_opening_entry_service.clone(),
pos_cash_movement_service: module.pos_cash_movement_service.clone(),
pos_discount_service: module.pos_discount_service.clone(),
pos_manager_pin_service: module.pos_manager_pin_service.clone(),
pos_floor_plan_service: module.pos_floor_plan_service.clone(),
pos_table_service: module.pos_table_service.clone(),
}
}
}
#[derive(Default)]
pub struct AppStateBuilder {
pos_closing_entry_service: Option<Arc<PosClosingEntryService>>,
pos_invoice_service: Option<Arc<PosInvoiceService>>,
pos_invoice_item_service: Option<Arc<PosInvoiceItemService>>,
pos_payment_service: Option<Arc<PosPaymentService>>,
pos_profile_service: Option<Arc<PosProfileService>>,
pos_opening_entry_service: Option<Arc<PosOpeningEntryService>>,
pos_cash_movement_service: Option<Arc<PosCashMovementService>>,
pos_discount_service: Option<Arc<PosDiscountService>>,
pos_manager_pin_service: Option<Arc<PosManagerPinService>>,
pos_floor_plan_service: Option<Arc<PosFloorPlanService>>,
pos_table_service: Option<Arc<PosTableService>>,
}
impl AppStateBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn with_pos_closing_entry_service(mut self, service: Arc<PosClosingEntryService>) -> Self {
self.pos_closing_entry_service = Some(service);
self
}
pub fn with_pos_invoice_service(mut self, service: Arc<PosInvoiceService>) -> Self {
self.pos_invoice_service = Some(service);
self
}
pub fn with_pos_invoice_item_service(mut self, service: Arc<PosInvoiceItemService>) -> Self {
self.pos_invoice_item_service = Some(service);
self
}
pub fn with_pos_payment_service(mut self, service: Arc<PosPaymentService>) -> Self {
self.pos_payment_service = Some(service);
self
}
pub fn with_pos_profile_service(mut self, service: Arc<PosProfileService>) -> Self {
self.pos_profile_service = Some(service);
self
}
pub fn with_pos_opening_entry_service(mut self, service: Arc<PosOpeningEntryService>) -> Self {
self.pos_opening_entry_service = Some(service);
self
}
pub fn with_pos_cash_movement_service(mut self, service: Arc<PosCashMovementService>) -> Self {
self.pos_cash_movement_service = Some(service);
self
}
pub fn with_pos_discount_service(mut self, service: Arc<PosDiscountService>) -> Self {
self.pos_discount_service = Some(service);
self
}
pub fn with_pos_manager_pin_service(mut self, service: Arc<PosManagerPinService>) -> Self {
self.pos_manager_pin_service = Some(service);
self
}
pub fn with_pos_floor_plan_service(mut self, service: Arc<PosFloorPlanService>) -> Self {
self.pos_floor_plan_service = Some(service);
self
}
pub fn with_pos_table_service(mut self, service: Arc<PosTableService>) -> Self {
self.pos_table_service = Some(service);
self
}
pub fn build(self) -> AppState {
AppState {
pos_closing_entry_service: self.pos_closing_entry_service.expect("pos_closing_entry_service is required"),
pos_invoice_service: self.pos_invoice_service.expect("pos_invoice_service is required"),
pos_invoice_item_service: self.pos_invoice_item_service.expect("pos_invoice_item_service is required"),
pos_payment_service: self.pos_payment_service.expect("pos_payment_service is required"),
pos_profile_service: self.pos_profile_service.expect("pos_profile_service is required"),
pos_opening_entry_service: self.pos_opening_entry_service.expect("pos_opening_entry_service is required"),
pos_cash_movement_service: self.pos_cash_movement_service.expect("pos_cash_movement_service is required"),
pos_discount_service: self.pos_discount_service.expect("pos_discount_service is required"),
pos_manager_pin_service: self.pos_manager_pin_service.expect("pos_manager_pin_service is required"),
pos_floor_plan_service: self.pos_floor_plan_service.expect("pos_floor_plan_service is required"),
pos_table_service: self.pos_table_service.expect("pos_table_service is required"),
}
}
}