backbone-pos 0.7.1

Point of sale — cashier session, ticket + multi-tender; orchestrates billing (revenue) + payment (settlement), posts no GL directly
Documentation
//! Pos Module Handlers
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This module provides:
//! - AppState dependency injection container
//! - Custom handler integration points

use std::sync::Arc;

// Import all services
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;

/// Application state for dependency injection.
///
/// This struct holds references to all module services
/// and is passed to HTTP handlers via Axum's State extractor.
///
/// # Example
///
/// ```ignore
/// use axum::extract::State;
///
/// async fn custom_handler(
///     State(state): State<AppState>,
/// ) -> impl IntoResponse {
///     // Access services via state
/// }
/// ```
#[derive(Clone)]
pub struct AppState {
    /// PosClosingEntry service
    pub pos_closing_entry_service: Arc<PosClosingEntryService>,
    /// PosInvoice service
    pub pos_invoice_service: Arc<PosInvoiceService>,
    /// PosInvoiceItem service
    pub pos_invoice_item_service: Arc<PosInvoiceItemService>,
    /// PosPayment service
    pub pos_payment_service: Arc<PosPaymentService>,
    /// PosProfile service
    pub pos_profile_service: Arc<PosProfileService>,
    /// PosOpeningEntry service
    pub pos_opening_entry_service: Arc<PosOpeningEntryService>,
    /// PosCashMovement service
    pub pos_cash_movement_service: Arc<PosCashMovementService>,
    /// PosDiscount service
    pub pos_discount_service: Arc<PosDiscountService>,
    /// PosManagerPin service
    pub pos_manager_pin_service: Arc<PosManagerPinService>,
    /// PosFloorPlan service
    pub pos_floor_plan_service: Arc<PosFloorPlanService>,
    /// PosTable service
    pub pos_table_service: Arc<PosTableService>,
}

impl AppState {
    /// Create a new AppState with all services.
    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,
        }
    }

    /// Create AppState from module instance.
    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(),
        }
    }
}

/// Builder for AppState.
///
/// Allows incremental construction of AppState.
#[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 {
    /// Create a new builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the PosClosingEntry service.
    pub fn with_pos_closing_entry_service(mut self, service: Arc<PosClosingEntryService>) -> Self {
        self.pos_closing_entry_service = Some(service);
        self
    }

    /// Set the PosInvoice service.
    pub fn with_pos_invoice_service(mut self, service: Arc<PosInvoiceService>) -> Self {
        self.pos_invoice_service = Some(service);
        self
    }

    /// Set the PosInvoiceItem service.
    pub fn with_pos_invoice_item_service(mut self, service: Arc<PosInvoiceItemService>) -> Self {
        self.pos_invoice_item_service = Some(service);
        self
    }

    /// Set the PosPayment service.
    pub fn with_pos_payment_service(mut self, service: Arc<PosPaymentService>) -> Self {
        self.pos_payment_service = Some(service);
        self
    }

    /// Set the PosProfile service.
    pub fn with_pos_profile_service(mut self, service: Arc<PosProfileService>) -> Self {
        self.pos_profile_service = Some(service);
        self
    }

    /// Set the PosOpeningEntry service.
    pub fn with_pos_opening_entry_service(mut self, service: Arc<PosOpeningEntryService>) -> Self {
        self.pos_opening_entry_service = Some(service);
        self
    }

    /// Set the PosCashMovement service.
    pub fn with_pos_cash_movement_service(mut self, service: Arc<PosCashMovementService>) -> Self {
        self.pos_cash_movement_service = Some(service);
        self
    }

    /// Set the PosDiscount service.
    pub fn with_pos_discount_service(mut self, service: Arc<PosDiscountService>) -> Self {
        self.pos_discount_service = Some(service);
        self
    }

    /// Set the PosManagerPin service.
    pub fn with_pos_manager_pin_service(mut self, service: Arc<PosManagerPinService>) -> Self {
        self.pos_manager_pin_service = Some(service);
        self
    }

    /// Set the PosFloorPlan service.
    pub fn with_pos_floor_plan_service(mut self, service: Arc<PosFloorPlanService>) -> Self {
        self.pos_floor_plan_service = Some(service);
        self
    }

    /// Set the PosTable service.
    pub fn with_pos_table_service(mut self, service: Arc<PosTableService>) -> Self {
        self.pos_table_service = Some(service);
        self
    }

    /// Build the AppState.
    ///
    /// # Panics
    ///
    /// Panics if any required service is not set.
    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"),
        }
    }
}