use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;
use crate::domain::entity::{FinancialStatement, StatementStatus, StatementType};
#[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
}
}
#[derive(Debug, Clone)]
pub struct FinancialStatementPaginatedResult {
pub data: Vec<FinancialStatement>,
pub total: u64,
pub page: u32,
pub per_page: u32,
}
#[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 {
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()
}
}
#[async_trait]
pub trait FinancialStatementRepository: Send + Sync {
async fn save(&self, entity: &FinancialStatement) -> Result<FinancialStatement>;
async fn find_by_id(&self, id: &str) -> Result<Option<FinancialStatement>>;
async fn find_all(&self) -> Result<Vec<FinancialStatement>>;
async fn update(&self, id: &str, entity: &FinancialStatement) -> Result<Option<FinancialStatement>>;
async fn delete(&self, id: &str) -> Result<bool>;
async fn list(&self, params: FinancialStatementPaginationParams) -> Result<FinancialStatementPaginatedResult>;
async fn list_with_filters(&self, params: FinancialStatementPaginationParams, filters: FinancialStatementFilter) -> Result<FinancialStatementPaginatedResult>;
async fn count(&self) -> Result<u64>;
async fn count_with_filters(&self, filters: FinancialStatementFilter) -> Result<u64>;
async fn exists(&self, id: &str) -> Result<bool>;
async fn soft_delete(&self, id: &str) -> Result<bool>;
async fn restore(&self, id: &str) -> Result<Option<FinancialStatement>>;
async fn list_deleted(&self, params: FinancialStatementPaginationParams) -> Result<FinancialStatementPaginatedResult>;
async fn empty_trash(&self) -> Result<u64>;
async fn bulk_save(&self, entities: &[FinancialStatement]) -> Result<Vec<FinancialStatement>>;
async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}