backbone-payroll 0.3.47

Payroll: salary structures, payroll runs and computed salary slips over effective-dated statutory tables, plus compensation changes
Documentation
//! Payroll 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::CompensationChangeService;
use crate::application::service::PayrollEntryService;
use crate::application::service::SalarySlipService;
use crate::application::service::SalarySlipLineService;
use crate::application::service::SalaryStructureService;
use crate::application::service::SalaryComponentService;

/// 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 {
    /// CompensationChange service
    pub compensation_change_service: Arc<CompensationChangeService>,
    /// PayrollEntry service
    pub payroll_entry_service: Arc<PayrollEntryService>,
    /// SalarySlip service
    pub salary_slip_service: Arc<SalarySlipService>,
    /// SalarySlipLine service
    pub salary_slip_line_service: Arc<SalarySlipLineService>,
    /// SalaryStructure service
    pub salary_structure_service: Arc<SalaryStructureService>,
    /// SalaryComponent service
    pub salary_component_service: Arc<SalaryComponentService>,
}

impl AppState {
    /// Create a new AppState with all services.
    pub fn new(
        compensation_change_service: Arc<CompensationChangeService>,
        payroll_entry_service: Arc<PayrollEntryService>,
        salary_slip_service: Arc<SalarySlipService>,
        salary_slip_line_service: Arc<SalarySlipLineService>,
        salary_structure_service: Arc<SalaryStructureService>,
        salary_component_service: Arc<SalaryComponentService>
    ) -> Self {
        Self {
            compensation_change_service,
            payroll_entry_service,
            salary_slip_service,
            salary_slip_line_service,
            salary_structure_service,
            salary_component_service,
        }
    }

    /// Create AppState from module instance.
    pub fn from_module(module: &crate::PayrollModule) -> Self {
        Self {
            compensation_change_service: module.compensation_change_service.clone(),
            payroll_entry_service: module.payroll_entry_service.clone(),
            salary_slip_service: module.salary_slip_service.clone(),
            salary_slip_line_service: module.salary_slip_line_service.clone(),
            salary_structure_service: module.salary_structure_service.clone(),
            salary_component_service: module.salary_component_service.clone(),
        }
    }
}

/// Builder for AppState.
///
/// Allows incremental construction of AppState.
#[derive(Default)]
pub struct AppStateBuilder {
    compensation_change_service: Option<Arc<CompensationChangeService>>,
    payroll_entry_service: Option<Arc<PayrollEntryService>>,
    salary_slip_service: Option<Arc<SalarySlipService>>,
    salary_slip_line_service: Option<Arc<SalarySlipLineService>>,
    salary_structure_service: Option<Arc<SalaryStructureService>>,
    salary_component_service: Option<Arc<SalaryComponentService>>,
}

impl AppStateBuilder {
    /// Create a new builder.
    pub fn new() -> Self {
        Self::default()
    }

    /// Set the CompensationChange service.
    pub fn with_compensation_change_service(mut self, service: Arc<CompensationChangeService>) -> Self {
        self.compensation_change_service = Some(service);
        self
    }

    /// Set the PayrollEntry service.
    pub fn with_payroll_entry_service(mut self, service: Arc<PayrollEntryService>) -> Self {
        self.payroll_entry_service = Some(service);
        self
    }

    /// Set the SalarySlip service.
    pub fn with_salary_slip_service(mut self, service: Arc<SalarySlipService>) -> Self {
        self.salary_slip_service = Some(service);
        self
    }

    /// Set the SalarySlipLine service.
    pub fn with_salary_slip_line_service(mut self, service: Arc<SalarySlipLineService>) -> Self {
        self.salary_slip_line_service = Some(service);
        self
    }

    /// Set the SalaryStructure service.
    pub fn with_salary_structure_service(mut self, service: Arc<SalaryStructureService>) -> Self {
        self.salary_structure_service = Some(service);
        self
    }

    /// Set the SalaryComponent service.
    pub fn with_salary_component_service(mut self, service: Arc<SalaryComponentService>) -> Self {
        self.salary_component_service = Some(service);
        self
    }

    /// Build the AppState.
    ///
    /// # Panics
    ///
    /// Panics if any required service is not set.
    pub fn build(self) -> AppState {
        AppState {
            compensation_change_service: self.compensation_change_service.expect("compensation_change_service is required"),
            payroll_entry_service: self.payroll_entry_service.expect("payroll_entry_service is required"),
            salary_slip_service: self.salary_slip_service.expect("salary_slip_service is required"),
            salary_slip_line_service: self.salary_slip_line_service.expect("salary_slip_line_service is required"),
            salary_structure_service: self.salary_structure_service.expect("salary_structure_service is required"),
            salary_component_service: self.salary_component_service.expect("salary_component_service is required"),
        }
    }
}