//! Reconciliation DTOs (Data Transfer Objects)
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! DTOs provide a clean separation between domain entities and API
//! representations, with validation and OpenAPI documentation support.
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc, NaiveDate};
use rust_decimal::Decimal;
#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
#[cfg(feature = "validation")]
use validator::Validate;
use crate::domain::entity::Reconciliation;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::ReconciliationStatus;
use crate::domain::entity::ReconciliationType;
// =============================================================================
// Create DTO
// =============================================================================
/// Request DTO for creating a new Reconciliation
///
/// Used in POST requests to create new entities.
/// Excludes auto-generated fields (id, created_at, updated_at, deleted_at).
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct CreateReconciliationDto {
#[cfg_attr(feature = "validation", validate(length(max = 30)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "reconciliation_number")]
pub reconciliation_number: String,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "account_id")]
pub account_id: Uuid,
#[cfg_attr(feature = "validation", validate(length(max = 20)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "account_number")]
pub account_number: String,
#[cfg_attr(feature = "validation", validate(length(max = 100)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "account_name")]
pub account_name: String,
#[serde(alias = "reconciliation_type")]
pub reconciliation_type: ReconciliationType,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(alias = "period_start")]
pub period_start: NaiveDate,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(alias = "period_end")]
pub period_end: NaiveDate,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(alias = "statement_date")]
pub statement_date: NaiveDate,
#[serde(alias = "opening_book_balance")]
pub opening_book_balance: Decimal,
#[serde(alias = "opening_statement_balance")]
pub opening_statement_balance: Decimal,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "previous_reconciliation_id")]
pub previous_reconciliation_id: Option<Uuid>,
#[serde(alias = "closing_book_balance")]
pub closing_book_balance: Decimal,
#[serde(alias = "closing_statement_balance")]
pub closing_statement_balance: Decimal,
#[serde(alias = "total_matched_debits")]
pub total_matched_debits: Decimal,
#[serde(alias = "total_matched_credits")]
pub total_matched_credits: Decimal,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "matched_count")]
pub matched_count: i32,
#[serde(alias = "total_unmatched_book_debits")]
pub total_unmatched_book_debits: Decimal,
#[serde(alias = "total_unmatched_book_credits")]
pub total_unmatched_book_credits: Decimal,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "unmatched_book_count")]
pub unmatched_book_count: i32,
#[serde(alias = "total_unmatched_statement_debits")]
pub total_unmatched_statement_debits: Decimal,
#[serde(alias = "total_unmatched_statement_credits")]
pub total_unmatched_statement_credits: Decimal,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "unmatched_statement_count")]
pub unmatched_statement_count: i32,
#[serde(alias = "outstanding_deposits")]
pub outstanding_deposits: Decimal,
#[serde(alias = "outstanding_checks")]
pub outstanding_checks: Decimal,
#[serde(alias = "deposits_in_transit")]
pub deposits_in_transit: Decimal,
#[serde(alias = "bank_charges")]
pub bank_charges: Decimal,
#[serde(alias = "bank_interest")]
pub bank_interest: Decimal,
#[serde(alias = "nsf_checks")]
pub nsf_checks: Decimal,
#[serde(alias = "other_adjustments")]
pub other_adjustments: Decimal,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "adjusted_book_balance")]
pub adjusted_book_balance: Option<Decimal>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "adjusted_statement_balance")]
pub adjusted_statement_balance: Option<Decimal>,
pub difference: Decimal,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_balanced")]
pub is_balanced: bool,
pub status: ReconciliationStatus,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "started_at")]
pub started_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "started_by")]
pub started_by: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "completed_at")]
pub completed_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "completed_by")]
pub completed_by: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "reviewed_at")]
pub reviewed_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "reviewed_by")]
pub reviewed_by: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "has_adjusting_entries")]
pub has_adjusting_entries: bool,
#[serde(alias = "adjusting_journal_ids")]
pub adjusting_journal_ids: serde_json::Value,
#[cfg_attr(feature = "validation", validate(length(max = 50)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "statement_source")]
pub statement_source: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 500)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "statement_file_url")]
pub statement_file_url: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "import_date")]
pub import_date: Option<DateTime<Utc>>,
#[cfg_attr(feature = "validation", validate(length(max = 1000)))]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 1000)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "discrepancy_notes")]
pub discrepancy_notes: Option<String>,
}
// =============================================================================
// Update DTO
// =============================================================================
/// Request DTO for full update of a Reconciliation
///
/// Used in PUT requests for full entity replacement.
/// All fields are required (except auto-generated ones).
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct UpdateReconciliationDto {
#[cfg_attr(feature = "validation", validate(length(max = 30)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "reconciliation_number")]
pub reconciliation_number: String,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "account_id")]
pub account_id: Uuid,
#[cfg_attr(feature = "validation", validate(length(max = 20)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "account_number")]
pub account_number: String,
#[cfg_attr(feature = "validation", validate(length(max = 100)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "account_name")]
pub account_name: String,
#[serde(alias = "reconciliation_type")]
pub reconciliation_type: ReconciliationType,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(alias = "period_start")]
pub period_start: NaiveDate,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(alias = "period_end")]
pub period_end: NaiveDate,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(alias = "statement_date")]
pub statement_date: NaiveDate,
#[serde(alias = "opening_book_balance")]
pub opening_book_balance: Decimal,
#[serde(alias = "opening_statement_balance")]
pub opening_statement_balance: Decimal,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "previous_reconciliation_id")]
pub previous_reconciliation_id: Option<Uuid>,
#[serde(alias = "closing_book_balance")]
pub closing_book_balance: Decimal,
#[serde(alias = "closing_statement_balance")]
pub closing_statement_balance: Decimal,
#[serde(alias = "total_matched_debits")]
pub total_matched_debits: Decimal,
#[serde(alias = "total_matched_credits")]
pub total_matched_credits: Decimal,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "matched_count")]
pub matched_count: i32,
#[serde(alias = "total_unmatched_book_debits")]
pub total_unmatched_book_debits: Decimal,
#[serde(alias = "total_unmatched_book_credits")]
pub total_unmatched_book_credits: Decimal,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "unmatched_book_count")]
pub unmatched_book_count: i32,
#[serde(alias = "total_unmatched_statement_debits")]
pub total_unmatched_statement_debits: Decimal,
#[serde(alias = "total_unmatched_statement_credits")]
pub total_unmatched_statement_credits: Decimal,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "unmatched_statement_count")]
pub unmatched_statement_count: i32,
#[serde(alias = "outstanding_deposits")]
pub outstanding_deposits: Decimal,
#[serde(alias = "outstanding_checks")]
pub outstanding_checks: Decimal,
#[serde(alias = "deposits_in_transit")]
pub deposits_in_transit: Decimal,
#[serde(alias = "bank_charges")]
pub bank_charges: Decimal,
#[serde(alias = "bank_interest")]
pub bank_interest: Decimal,
#[serde(alias = "nsf_checks")]
pub nsf_checks: Decimal,
#[serde(alias = "other_adjustments")]
pub other_adjustments: Decimal,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "adjusted_book_balance")]
pub adjusted_book_balance: Option<Decimal>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "adjusted_statement_balance")]
pub adjusted_statement_balance: Option<Decimal>,
pub difference: Decimal,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_balanced")]
pub is_balanced: bool,
pub status: ReconciliationStatus,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "started_at")]
pub started_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "started_by")]
pub started_by: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "completed_at")]
pub completed_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "completed_by")]
pub completed_by: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "reviewed_at")]
pub reviewed_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "reviewed_by")]
pub reviewed_by: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "has_adjusting_entries")]
pub has_adjusting_entries: bool,
#[serde(alias = "adjusting_journal_ids")]
pub adjusting_journal_ids: serde_json::Value,
#[cfg_attr(feature = "validation", validate(length(max = 50)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "statement_source")]
pub statement_source: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 500)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "statement_file_url")]
pub statement_file_url: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "import_date")]
pub import_date: Option<DateTime<Utc>>,
#[cfg_attr(feature = "validation", validate(length(max = 1000)))]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 1000)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "discrepancy_notes")]
pub discrepancy_notes: Option<String>,
}
// =============================================================================
// Patch DTO
// =============================================================================
/// Request DTO for partial update of a Reconciliation
///
/// Used in PATCH requests for partial updates.
/// All fields are optional - only provided fields will be updated.
#[derive(Debug, Clone, Default, Deserialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct PatchReconciliationDto {
#[cfg_attr(feature = "validation", validate(length(max = 30)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "reconciliation_number")]
pub reconciliation_number: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "account_id")]
pub account_id: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 20)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "account_number")]
pub account_number: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 100)))]
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "account_name")]
pub account_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "reconciliation_type")]
pub reconciliation_type: Option<ReconciliationType>,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "period_start")]
pub period_start: Option<NaiveDate>,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "period_end")]
pub period_end: Option<NaiveDate>,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "statement_date")]
pub statement_date: Option<NaiveDate>,
#[serde(skip_serializing_if = "Option::is_none", alias = "opening_book_balance")]
pub opening_book_balance: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "opening_statement_balance")]
pub opening_statement_balance: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "previous_reconciliation_id")]
pub previous_reconciliation_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "closing_book_balance")]
pub closing_book_balance: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "closing_statement_balance")]
pub closing_statement_balance: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "total_matched_debits")]
pub total_matched_debits: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "total_matched_credits")]
pub total_matched_credits: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(skip_serializing_if = "Option::is_none", alias = "matched_count")]
pub matched_count: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none", alias = "total_unmatched_book_debits")]
pub total_unmatched_book_debits: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "total_unmatched_book_credits")]
pub total_unmatched_book_credits: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(skip_serializing_if = "Option::is_none", alias = "unmatched_book_count")]
pub unmatched_book_count: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none", alias = "total_unmatched_statement_debits")]
pub total_unmatched_statement_debits: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "total_unmatched_statement_credits")]
pub total_unmatched_statement_credits: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(skip_serializing_if = "Option::is_none", alias = "unmatched_statement_count")]
pub unmatched_statement_count: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none", alias = "outstanding_deposits")]
pub outstanding_deposits: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "outstanding_checks")]
pub outstanding_checks: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "deposits_in_transit")]
pub deposits_in_transit: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "bank_charges")]
pub bank_charges: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "bank_interest")]
pub bank_interest: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "nsf_checks")]
pub nsf_checks: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "other_adjustments")]
pub other_adjustments: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "adjusted_book_balance")]
pub adjusted_book_balance: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "adjusted_statement_balance")]
pub adjusted_statement_balance: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none")]
pub difference: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "is_balanced")]
pub is_balanced: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<ReconciliationStatus>,
#[serde(skip_serializing_if = "Option::is_none", alias = "started_at")]
pub started_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none", alias = "started_by")]
pub started_by: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "completed_at")]
pub completed_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none", alias = "completed_by")]
pub completed_by: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "reviewed_at")]
pub reviewed_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none", alias = "reviewed_by")]
pub reviewed_by: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "has_adjusting_entries")]
pub has_adjusting_entries: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none", alias = "adjusting_journal_ids")]
pub adjusting_journal_ids: Option<serde_json::Value>,
#[cfg_attr(feature = "validation", validate(length(max = 50)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "statement_source")]
pub statement_source: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 500)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "statement_file_url")]
pub statement_file_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "import_date")]
pub import_date: Option<DateTime<Utc>>,
#[cfg_attr(feature = "validation", validate(length(max = 1000)))]
#[serde(skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 1000)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "discrepancy_notes")]
pub discrepancy_notes: Option<String>,
}
impl PatchReconciliationDto {
/// Check if any field is set
pub fn has_changes(&self) -> bool {
self.reconciliation_number.is_some() || self.account_id.is_some() || self.account_number.is_some() || self.account_name.is_some() || self.reconciliation_type.is_some() || self.period_start.is_some() || self.period_end.is_some() || self.statement_date.is_some() || self.opening_book_balance.is_some() || self.opening_statement_balance.is_some() || self.previous_reconciliation_id.is_some() || self.closing_book_balance.is_some() || self.closing_statement_balance.is_some() || self.total_matched_debits.is_some() || self.total_matched_credits.is_some() || self.matched_count.is_some() || self.total_unmatched_book_debits.is_some() || self.total_unmatched_book_credits.is_some() || self.unmatched_book_count.is_some() || self.total_unmatched_statement_debits.is_some() || self.total_unmatched_statement_credits.is_some() || self.unmatched_statement_count.is_some() || self.outstanding_deposits.is_some() || self.outstanding_checks.is_some() || self.deposits_in_transit.is_some() || self.bank_charges.is_some() || self.bank_interest.is_some() || self.nsf_checks.is_some() || self.other_adjustments.is_some() || self.adjusted_book_balance.is_some() || self.adjusted_statement_balance.is_some() || self.difference.is_some() || self.is_balanced.is_some() || self.status.is_some() || self.started_at.is_some() || self.started_by.is_some() || self.completed_at.is_some() || self.completed_by.is_some() || self.reviewed_at.is_some() || self.reviewed_by.is_some() || self.has_adjusting_entries.is_some() || self.adjusting_journal_ids.is_some() || self.statement_source.is_some() || self.statement_file_url.is_some() || self.import_date.is_some() || self.notes.is_some() || self.discrepancy_notes.is_some()
}
}
// =============================================================================
// Response DTO
// =============================================================================
/// Response DTO for Reconciliation entity
///
/// Used in API responses for single entity.
/// Includes all fields including metadata.
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct ReconciliationResponseDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub reconciliation_number: String,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub account_id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub account_number: String,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub account_name: String,
pub reconciliation_type: ReconciliationType,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
pub period_start: NaiveDate,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
pub period_end: NaiveDate,
#[cfg_attr(feature = "openapi", schema(example = "2024-01-01"))]
pub statement_date: NaiveDate,
pub opening_book_balance: Decimal,
pub opening_statement_balance: Decimal,
pub previous_reconciliation_id: Option<Uuid>,
pub closing_book_balance: Decimal,
pub closing_statement_balance: Decimal,
pub total_matched_debits: Decimal,
pub total_matched_credits: Decimal,
#[cfg_attr(feature = "openapi", schema(example = 42))]
pub matched_count: i32,
pub total_unmatched_book_debits: Decimal,
pub total_unmatched_book_credits: Decimal,
#[cfg_attr(feature = "openapi", schema(example = 42))]
pub unmatched_book_count: i32,
pub total_unmatched_statement_debits: Decimal,
pub total_unmatched_statement_credits: Decimal,
#[cfg_attr(feature = "openapi", schema(example = 42))]
pub unmatched_statement_count: i32,
pub outstanding_deposits: Decimal,
pub outstanding_checks: Decimal,
pub deposits_in_transit: Decimal,
pub bank_charges: Decimal,
pub bank_interest: Decimal,
pub nsf_checks: Decimal,
pub other_adjustments: Decimal,
pub adjusted_book_balance: Option<Decimal>,
pub adjusted_statement_balance: Option<Decimal>,
pub difference: Decimal,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub is_balanced: bool,
pub status: ReconciliationStatus,
pub started_at: Option<DateTime<Utc>>,
pub started_by: Option<Uuid>,
pub completed_at: Option<DateTime<Utc>>,
pub completed_by: Option<Uuid>,
pub reviewed_at: Option<DateTime<Utc>>,
pub reviewed_by: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub has_adjusting_entries: bool,
pub adjusting_journal_ids: serde_json::Value,
pub statement_source: Option<String>,
pub statement_file_url: Option<String>,
pub import_date: Option<DateTime<Utc>>,
pub notes: Option<String>,
pub discrepancy_notes: Option<String>,
pub metadata: AuditMetadata,
}
// =============================================================================
// List Response DTO
// =============================================================================
/// Paginated list response for Reconciliation entities
///
/// Used in API responses for list endpoints.
/// Includes pagination metadata.
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct ReconciliationListResponseDto {
/// List of items
pub items: Vec<ReconciliationResponseDto>,
/// Total number of items (across all pages)
pub total: u64,
/// Current page number (1-indexed)
pub page: u32,
/// Number of items per page
pub per_page: u32,
/// Total number of pages
pub total_pages: u32,
/// Whether there is a next page
pub has_next: bool,
/// Whether there is a previous page
pub has_prev: bool,
}
impl ReconciliationListResponseDto {
/// Create a new list response from items and pagination info
pub fn new(items: Vec<ReconciliationResponseDto>, total: u64, page: u32, per_page: u32) -> Self {
let total_pages = if per_page > 0 {
((total as f64) / (per_page as f64)).ceil() as u32
} else {
0
};
Self {
items,
total,
page,
per_page,
total_pages,
has_next: page < total_pages,
has_prev: page > 1,
}
}
}
/// Summary DTO for list views (compact version)
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct ReconciliationSummaryDto {
pub id: Uuid,
pub reconciliation_number: String,
pub account_id: Uuid,
pub account_number: String,
pub created_at: Option<DateTime<Utc>>,
}
// =============================================================================
// Conversions
// =============================================================================
impl From<Reconciliation> for ReconciliationResponseDto {
fn from(entity: Reconciliation) -> Self {
Self {
id: entity.id,
reconciliation_number: entity.reconciliation_number,
account_id: entity.account_id,
account_number: entity.account_number,
account_name: entity.account_name,
reconciliation_type: entity.reconciliation_type,
period_start: entity.period_start,
period_end: entity.period_end,
statement_date: entity.statement_date,
opening_book_balance: entity.opening_book_balance,
opening_statement_balance: entity.opening_statement_balance,
previous_reconciliation_id: entity.previous_reconciliation_id,
closing_book_balance: entity.closing_book_balance,
closing_statement_balance: entity.closing_statement_balance,
total_matched_debits: entity.total_matched_debits,
total_matched_credits: entity.total_matched_credits,
matched_count: entity.matched_count,
total_unmatched_book_debits: entity.total_unmatched_book_debits,
total_unmatched_book_credits: entity.total_unmatched_book_credits,
unmatched_book_count: entity.unmatched_book_count,
total_unmatched_statement_debits: entity.total_unmatched_statement_debits,
total_unmatched_statement_credits: entity.total_unmatched_statement_credits,
unmatched_statement_count: entity.unmatched_statement_count,
outstanding_deposits: entity.outstanding_deposits,
outstanding_checks: entity.outstanding_checks,
deposits_in_transit: entity.deposits_in_transit,
bank_charges: entity.bank_charges,
bank_interest: entity.bank_interest,
nsf_checks: entity.nsf_checks,
other_adjustments: entity.other_adjustments,
adjusted_book_balance: entity.adjusted_book_balance,
adjusted_statement_balance: entity.adjusted_statement_balance,
difference: entity.difference,
is_balanced: entity.is_balanced,
status: entity.status,
started_at: entity.started_at,
started_by: entity.started_by,
completed_at: entity.completed_at,
completed_by: entity.completed_by,
reviewed_at: entity.reviewed_at,
reviewed_by: entity.reviewed_by,
has_adjusting_entries: entity.has_adjusting_entries,
adjusting_journal_ids: entity.adjusting_journal_ids,
statement_source: entity.statement_source,
statement_file_url: entity.statement_file_url,
import_date: entity.import_date,
notes: entity.notes,
discrepancy_notes: entity.discrepancy_notes,
metadata: entity.metadata,
}
}
}
impl From<Reconciliation> for ReconciliationSummaryDto {
fn from(entity: Reconciliation) -> Self {
let created_at = backbone_core::PersistentEntity::created_at(&entity);
Self {
id: entity.id,
reconciliation_number: entity.reconciliation_number,
account_id: entity.account_id,
account_number: entity.account_number,
created_at,
}
}
}
impl From<CreateReconciliationDto> for Reconciliation {
fn from(dto: CreateReconciliationDto) -> Self {
Self {
id: Uuid::new_v4(),
reconciliation_number: dto.reconciliation_number,
account_id: dto.account_id,
account_number: dto.account_number,
account_name: dto.account_name,
reconciliation_type: dto.reconciliation_type,
period_start: dto.period_start,
period_end: dto.period_end,
statement_date: dto.statement_date,
opening_book_balance: dto.opening_book_balance,
opening_statement_balance: dto.opening_statement_balance,
previous_reconciliation_id: dto.previous_reconciliation_id,
closing_book_balance: dto.closing_book_balance,
closing_statement_balance: dto.closing_statement_balance,
total_matched_debits: dto.total_matched_debits,
total_matched_credits: dto.total_matched_credits,
matched_count: dto.matched_count,
total_unmatched_book_debits: dto.total_unmatched_book_debits,
total_unmatched_book_credits: dto.total_unmatched_book_credits,
unmatched_book_count: dto.unmatched_book_count,
total_unmatched_statement_debits: dto.total_unmatched_statement_debits,
total_unmatched_statement_credits: dto.total_unmatched_statement_credits,
unmatched_statement_count: dto.unmatched_statement_count,
outstanding_deposits: dto.outstanding_deposits,
outstanding_checks: dto.outstanding_checks,
deposits_in_transit: dto.deposits_in_transit,
bank_charges: dto.bank_charges,
bank_interest: dto.bank_interest,
nsf_checks: dto.nsf_checks,
other_adjustments: dto.other_adjustments,
adjusted_book_balance: dto.adjusted_book_balance,
adjusted_statement_balance: dto.adjusted_statement_balance,
difference: dto.difference,
is_balanced: dto.is_balanced,
status: dto.status,
started_at: dto.started_at,
started_by: dto.started_by,
completed_at: dto.completed_at,
completed_by: dto.completed_by,
reviewed_at: dto.reviewed_at,
reviewed_by: dto.reviewed_by,
has_adjusting_entries: dto.has_adjusting_entries,
adjusting_journal_ids: dto.adjusting_journal_ids,
statement_source: dto.statement_source,
statement_file_url: dto.statement_file_url,
import_date: dto.import_date,
notes: dto.notes,
discrepancy_notes: dto.discrepancy_notes,
metadata: AuditMetadata::default(),
}
}
}
impl From<&Reconciliation> for ReconciliationResponseDto {
fn from(entity: &Reconciliation) -> Self {
Self {
id: entity.id.clone(),
reconciliation_number: entity.reconciliation_number.clone(),
account_id: entity.account_id.clone(),
account_number: entity.account_number.clone(),
account_name: entity.account_name.clone(),
reconciliation_type: entity.reconciliation_type.clone(),
period_start: entity.period_start.clone(),
period_end: entity.period_end.clone(),
statement_date: entity.statement_date.clone(),
opening_book_balance: entity.opening_book_balance.clone(),
opening_statement_balance: entity.opening_statement_balance.clone(),
previous_reconciliation_id: entity.previous_reconciliation_id.clone(),
closing_book_balance: entity.closing_book_balance.clone(),
closing_statement_balance: entity.closing_statement_balance.clone(),
total_matched_debits: entity.total_matched_debits.clone(),
total_matched_credits: entity.total_matched_credits.clone(),
matched_count: entity.matched_count.clone(),
total_unmatched_book_debits: entity.total_unmatched_book_debits.clone(),
total_unmatched_book_credits: entity.total_unmatched_book_credits.clone(),
unmatched_book_count: entity.unmatched_book_count.clone(),
total_unmatched_statement_debits: entity.total_unmatched_statement_debits.clone(),
total_unmatched_statement_credits: entity.total_unmatched_statement_credits.clone(),
unmatched_statement_count: entity.unmatched_statement_count.clone(),
outstanding_deposits: entity.outstanding_deposits.clone(),
outstanding_checks: entity.outstanding_checks.clone(),
deposits_in_transit: entity.deposits_in_transit.clone(),
bank_charges: entity.bank_charges.clone(),
bank_interest: entity.bank_interest.clone(),
nsf_checks: entity.nsf_checks.clone(),
other_adjustments: entity.other_adjustments.clone(),
adjusted_book_balance: entity.adjusted_book_balance.clone(),
adjusted_statement_balance: entity.adjusted_statement_balance.clone(),
difference: entity.difference.clone(),
is_balanced: entity.is_balanced.clone(),
status: entity.status.clone(),
started_at: entity.started_at.clone(),
started_by: entity.started_by.clone(),
completed_at: entity.completed_at.clone(),
completed_by: entity.completed_by.clone(),
reviewed_at: entity.reviewed_at.clone(),
reviewed_by: entity.reviewed_by.clone(),
has_adjusting_entries: entity.has_adjusting_entries.clone(),
adjusting_journal_ids: entity.adjusting_journal_ids.clone(),
statement_source: entity.statement_source.clone(),
statement_file_url: entity.statement_file_url.clone(),
import_date: entity.import_date.clone(),
notes: entity.notes.clone(),
discrepancy_notes: entity.discrepancy_notes.clone(),
metadata: entity.metadata.clone(),
}
}
}
impl backbone_core::FromCreateDto<CreateReconciliationDto> for Reconciliation {
fn from_create_dto(dto: CreateReconciliationDto) -> backbone_core::ServiceResult<Self> {
Ok(Reconciliation::from(dto))
}
}
impl backbone_core::ApplyUpdateDto<UpdateReconciliationDto> for Reconciliation {
fn apply_update(mut self, dto: UpdateReconciliationDto) -> backbone_core::ServiceResult<Self> {
self.reconciliation_number = dto.reconciliation_number;
self.account_id = dto.account_id;
self.account_number = dto.account_number;
self.account_name = dto.account_name;
self.reconciliation_type = dto.reconciliation_type;
self.period_start = dto.period_start;
self.period_end = dto.period_end;
self.statement_date = dto.statement_date;
self.opening_book_balance = dto.opening_book_balance;
self.opening_statement_balance = dto.opening_statement_balance;
self.previous_reconciliation_id = dto.previous_reconciliation_id;
self.closing_book_balance = dto.closing_book_balance;
self.closing_statement_balance = dto.closing_statement_balance;
self.total_matched_debits = dto.total_matched_debits;
self.total_matched_credits = dto.total_matched_credits;
self.matched_count = dto.matched_count;
self.total_unmatched_book_debits = dto.total_unmatched_book_debits;
self.total_unmatched_book_credits = dto.total_unmatched_book_credits;
self.unmatched_book_count = dto.unmatched_book_count;
self.total_unmatched_statement_debits = dto.total_unmatched_statement_debits;
self.total_unmatched_statement_credits = dto.total_unmatched_statement_credits;
self.unmatched_statement_count = dto.unmatched_statement_count;
self.outstanding_deposits = dto.outstanding_deposits;
self.outstanding_checks = dto.outstanding_checks;
self.deposits_in_transit = dto.deposits_in_transit;
self.bank_charges = dto.bank_charges;
self.bank_interest = dto.bank_interest;
self.nsf_checks = dto.nsf_checks;
self.other_adjustments = dto.other_adjustments;
self.adjusted_book_balance = dto.adjusted_book_balance;
self.adjusted_statement_balance = dto.adjusted_statement_balance;
self.difference = dto.difference;
self.is_balanced = dto.is_balanced;
self.status = dto.status;
self.started_at = dto.started_at;
self.started_by = dto.started_by;
self.completed_at = dto.completed_at;
self.completed_by = dto.completed_by;
self.reviewed_at = dto.reviewed_at;
self.reviewed_by = dto.reviewed_by;
self.has_adjusting_entries = dto.has_adjusting_entries;
self.adjusting_journal_ids = dto.adjusting_journal_ids;
self.statement_source = dto.statement_source;
self.statement_file_url = dto.statement_file_url;
self.import_date = dto.import_date;
self.notes = dto.notes;
self.discrepancy_notes = dto.discrepancy_notes;
Ok(self)
}
}
// =============================================================================
// Custom DTOs
// =============================================================================
// <<< CUSTOM DTOs
// Add custom DTOs specific to Reconciliation here.
// This section will be preserved during regeneration.
// >>> END CUSTOM DTOs