backbone-payroll 0.3.47

Payroll: salary structures, payroll runs and computed salary slips over effective-dated statutory tables, plus compensation changes
Documentation
//! Repository trait for CompensationChange aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the CompensationChange aggregate.
//! Implementation is in the infrastructure layer.

use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;

use crate::domain::entity::{CompensationChange, CompensationChangeType};

/// Pagination parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct CompensationChangePaginationParams {
    pub page: u32,
    pub per_page: u32,
}

impl CompensationChangePaginationParams {
    pub fn new(page: u32, per_page: u32) -> Self {
        Self { page, per_page }
    }

    pub fn offset(&self) -> u64 {
        ((self.page.saturating_sub(1)) * self.per_page) as u64
    }

    pub fn limit(&self) -> u64 {
        self.per_page as u64
    }
}

/// Paginated result for list queries
#[derive(Debug, Clone)]
pub struct CompensationChangePaginatedResult {
    pub data: Vec<CompensationChange>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct CompensationChangeFilter {
    pub employee_id: Option<Uuid>,
    pub change_type: Option<CompensationChangeType>,
    pub reference_id: Option<Uuid>,
    pub note: Option<String>,
}

impl CompensationChangeFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.employee_id.is_some() || self.change_type.is_some() || self.reference_id.is_some() || self.note.is_some()
    }
}

/// Repository trait for CompensationChange aggregate
///
/// This trait defines the persistence contract for CompensationChange entities.
/// Implementations should be in the infrastructure layer.
#[async_trait]
pub trait CompensationChangeRepository: Send + Sync {

    // =========================================================================
    // Core CRUD Operations
    // =========================================================================

    /// Save a new compensation_change entity
    async fn save(&self, entity: &CompensationChange) -> Result<CompensationChange>;

    /// Find compensation_change by ID
    async fn find_by_id(&self, id: &str) -> Result<Option<CompensationChange>>;

    /// Find all compensation_change entities
    async fn find_all(&self) -> Result<Vec<CompensationChange>>;

    /// Update compensation_change by ID
    async fn update(&self, id: &str, entity: &CompensationChange) -> Result<Option<CompensationChange>>;

    /// Delete compensation_change by ID
    async fn delete(&self, id: &str) -> Result<bool>;

    // =========================================================================
    // Pagination
    // =========================================================================

    /// List compensation_change with pagination
    async fn list(&self, params: CompensationChangePaginationParams) -> Result<CompensationChangePaginatedResult>;

    /// List compensation_change with pagination and filters
    async fn list_with_filters(&self, params: CompensationChangePaginationParams, filters: CompensationChangeFilter) -> Result<CompensationChangePaginatedResult>;

    /// Count all compensation_change entities
    async fn count(&self) -> Result<u64>;

    /// Count compensation_change entities matching filters
    async fn count_with_filters(&self, filters: CompensationChangeFilter) -> Result<u64>;

    /// Check if compensation_change exists by ID
    async fn exists(&self, id: &str) -> Result<bool>;

    // =========================================================================
    // Soft Delete Operations
    // =========================================================================

    /// Soft delete compensation_change by ID
    async fn soft_delete(&self, id: &str) -> Result<bool>;

    /// Restore soft-deleted compensation_change by ID
    async fn restore(&self, id: &str) -> Result<Option<CompensationChange>>;

    /// List soft-deleted compensation_change entities
    async fn list_deleted(&self, params: CompensationChangePaginationParams) -> Result<CompensationChangePaginatedResult>;

    /// Empty trash (permanently delete all soft-deleted entities)
    async fn empty_trash(&self) -> Result<u64>;

    // =========================================================================
    // Bulk Operations
    // =========================================================================

    /// Bulk save compensation_change entities
    async fn bulk_save(&self, entities: &[CompensationChange]) -> Result<Vec<CompensationChange>>;

    /// Bulk delete by IDs
    async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}