backbone-accounting 0.15.0

GL, journals, ledger, reconciliation (extracted from bersihir)
Documentation
//! Repository trait for FinancialStatement aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the FinancialStatement aggregate.
//! Implementation is in the infrastructure layer.

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

use crate::domain::entity::{FinancialStatement, StatementStatus, StatementType};

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

impl FinancialStatementPaginationParams {
    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 FinancialStatementPaginatedResult {
    pub data: Vec<FinancialStatement>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct FinancialStatementFilter {
    pub statement_number: Option<String>,
    pub statement_type: Option<StatementType>,
    pub name: Option<String>,
    pub fiscal_period_id: Option<Uuid>,
    pub is_comparative: Option<bool>,
    pub comparative_period_id: Option<Uuid>,
    pub status: Option<StatementStatus>,
    pub balance_check: Option<bool>,
    pub trial_balance_check: Option<bool>,
    pub management_notes: Option<String>,
    pub generated_by: Option<Uuid>,
    pub reviewed_by: Option<Uuid>,
    pub approved_by: Option<Uuid>,
    pub pdf_url: Option<String>,
    pub excel_url: Option<String>,
    pub currency: Option<String>,
}

impl FinancialStatementFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.statement_number.is_some() || self.statement_type.is_some() || self.name.is_some() || self.fiscal_period_id.is_some() || self.is_comparative.is_some() || self.comparative_period_id.is_some() || self.status.is_some() || self.balance_check.is_some() || self.trial_balance_check.is_some() || self.management_notes.is_some() || self.generated_by.is_some() || self.reviewed_by.is_some() || self.approved_by.is_some() || self.pdf_url.is_some() || self.excel_url.is_some() || self.currency.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List financial_statement with pagination
    async fn list(&self, params: FinancialStatementPaginationParams) -> Result<FinancialStatementPaginatedResult>;

    /// List financial_statement with pagination and filters
    async fn list_with_filters(&self, params: FinancialStatementPaginationParams, filters: FinancialStatementFilter) -> Result<FinancialStatementPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted financial_statement entities
    async fn list_deleted(&self, params: FinancialStatementPaginationParams) -> Result<FinancialStatementPaginatedResult>;

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

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

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

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