//! Repository trait for Ledger aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the Ledger aggregate.
//! Implementation is in the infrastructure layer.
use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;
use crate::domain::entity::{Ledger, AccountType, NormalBalance, PartyType};
/// Pagination parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct LedgerPaginationParams {
pub page: u32,
pub per_page: u32,
}
impl LedgerPaginationParams {
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 LedgerPaginatedResult {
pub data: Vec<Ledger>,
pub total: u64,
pub page: u32,
pub per_page: u32,
}
/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct LedgerFilter {
pub account_id: Option<Uuid>,
pub account_number: Option<String>,
pub account_name: Option<String>,
pub account_type: Option<AccountType>,
pub normal_balance: Option<NormalBalance>,
pub journal_id: Option<Uuid>,
pub journal_number: Option<String>,
pub journal_line_id: Option<Uuid>,
pub fiscal_period_id: Option<Uuid>,
pub description: Option<String>,
pub reference: Option<String>,
pub currency: Option<String>,
pub branch_id: Option<Uuid>,
pub party_type: Option<PartyType>,
pub party_id: Option<Uuid>,
pub cost_center_id: Option<Uuid>,
pub project_id: Option<Uuid>,
pub department_id: Option<Uuid>,
pub source_type: Option<String>,
pub source_id: Option<Uuid>,
pub source_reference: Option<String>,
pub is_reconciled: Option<bool>,
pub reconciliation_id: Option<Uuid>,
pub is_opening_balance: Option<bool>,
pub is_closing_entry: Option<bool>,
pub is_adjustment: Option<bool>,
pub is_reversed: Option<bool>,
pub reversed_by_id: Option<Uuid>,
pub reverses_id: Option<Uuid>,
}
impl LedgerFilter {
/// Check if any filter is set
pub fn has_filters(&self) -> bool {
self.account_id.is_some() || self.account_number.is_some() || self.account_name.is_some() || self.account_type.is_some() || self.normal_balance.is_some() || self.journal_id.is_some() || self.journal_number.is_some() || self.journal_line_id.is_some() || self.fiscal_period_id.is_some() || self.description.is_some() || self.reference.is_some() || self.currency.is_some() || self.branch_id.is_some() || self.party_type.is_some() || self.party_id.is_some() || self.cost_center_id.is_some() || self.project_id.is_some() || self.department_id.is_some() || self.source_type.is_some() || self.source_id.is_some() || self.source_reference.is_some() || self.is_reconciled.is_some() || self.reconciliation_id.is_some() || self.is_opening_balance.is_some() || self.is_closing_entry.is_some() || self.is_adjustment.is_some() || self.is_reversed.is_some() || self.reversed_by_id.is_some() || self.reverses_id.is_some()
}
}
/// Repository trait for Ledger aggregate
///
/// This trait defines the persistence contract for Ledger entities.
/// Implementations should be in the infrastructure layer.
#[async_trait]
pub trait LedgerRepository: Send + Sync {
// =========================================================================
// Core CRUD Operations
// =========================================================================
/// Save a new ledger entity
async fn save(&self, entity: &Ledger) -> Result<Ledger>;
/// Find ledger by ID
async fn find_by_id(&self, id: &str) -> Result<Option<Ledger>>;
/// Find all ledger entities
async fn find_all(&self) -> Result<Vec<Ledger>>;
/// Update ledger by ID
async fn update(&self, id: &str, entity: &Ledger) -> Result<Option<Ledger>>;
/// Delete ledger by ID
async fn delete(&self, id: &str) -> Result<bool>;
// =========================================================================
// Pagination
// =========================================================================
/// List ledger with pagination
async fn list(&self, params: LedgerPaginationParams) -> Result<LedgerPaginatedResult>;
/// List ledger with pagination and filters
async fn list_with_filters(&self, params: LedgerPaginationParams, filters: LedgerFilter) -> Result<LedgerPaginatedResult>;
/// Count all ledger entities
async fn count(&self) -> Result<u64>;
/// Count ledger entities matching filters
async fn count_with_filters(&self, filters: LedgerFilter) -> Result<u64>;
/// Check if ledger exists by ID
async fn exists(&self, id: &str) -> Result<bool>;
// =========================================================================
// Soft Delete Operations
// =========================================================================
/// Soft delete ledger by ID
async fn soft_delete(&self, id: &str) -> Result<bool>;
/// Restore soft-deleted ledger by ID
async fn restore(&self, id: &str) -> Result<Option<Ledger>>;
/// List soft-deleted ledger entities
async fn list_deleted(&self, params: LedgerPaginationParams) -> Result<LedgerPaginatedResult>;
/// Empty trash (permanently delete all soft-deleted entities)
async fn empty_trash(&self) -> Result<u64>;
// =========================================================================
// Bulk Operations
// =========================================================================
/// Bulk save ledger entities
async fn bulk_save(&self, entities: &[Ledger]) -> Result<Vec<Ledger>>;
/// Bulk delete by IDs
async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}