backbone-accounting 0.18.0

GL, journals, ledger, reconciliation (extracted from bersihir)
Documentation
//! PrintedCheck DTOs (Data Transfer Objects)
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! DTOs provide a clean separation between domain entities and API
//! representations, with OpenAPI documentation support.

use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;

#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

use crate::domain::entity::PrintedCheck;

// =============================================================================
// Create DTO
// =============================================================================

/// Request DTO for creating a new PrintedCheck
///
/// 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))]
#[serde(rename_all = "camelCase")]
pub struct CreatePrintedCheckDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "bank_account_id")]
    pub bank_account_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "payment_id")]
    pub payment_id: Uuid,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "payment_number")]
    pub payment_number: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "check_number")]
    pub check_number: String,
    pub amount: Decimal,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "payee_name")]
    pub payee_name: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub status: String,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    #[serde(alias = "printed_at")]
    pub printed_at: DateTime<Utc>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "printed_by")]
    pub printed_by: Option<Uuid>,
}

// =============================================================================
// Update DTO
// =============================================================================

/// Request DTO for full update of a PrintedCheck
///
/// 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))]
#[serde(rename_all = "camelCase")]
pub struct UpdatePrintedCheckDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "bank_account_id")]
    pub bank_account_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "payment_id")]
    pub payment_id: Uuid,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "payment_number")]
    pub payment_number: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "check_number")]
    pub check_number: String,
    pub amount: Decimal,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "payee_name")]
    pub payee_name: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub status: String,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    #[serde(alias = "printed_at")]
    pub printed_at: DateTime<Utc>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "printed_by")]
    pub printed_by: Option<Uuid>,
}

// =============================================================================
// Patch DTO
// =============================================================================

/// Request DTO for partial update of a PrintedCheck
///
/// 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))]
#[serde(rename_all = "camelCase")]
pub struct PatchPrintedCheckDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "bank_account_id")]
    pub bank_account_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "payment_id")]
    pub payment_id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "payment_number")]
    pub payment_number: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "check_number")]
    pub check_number: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub amount: Option<Decimal>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "payee_name")]
    pub payee_name: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "printed_at")]
    pub printed_at: Option<DateTime<Utc>>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "printed_by")]
    pub printed_by: Option<Uuid>,
}

impl PatchPrintedCheckDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.bank_account_id.is_some() || self.payment_id.is_some() || self.payment_number.is_some() || self.check_number.is_some() || self.amount.is_some() || self.payee_name.is_some() || self.status.is_some() || self.printed_at.is_some() || self.printed_by.is_some()
    }
}

// =============================================================================
// Response DTO
// =============================================================================

/// Response DTO for PrintedCheck 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 PrintedCheckResponseDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub bank_account_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub payment_id: Uuid,
    pub payment_number: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub check_number: String,
    pub amount: Decimal,
    pub payee_name: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub status: String,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    pub printed_at: DateTime<Utc>,
    pub printed_by: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    pub created_at: DateTime<Utc>,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    pub updated_at: DateTime<Utc>,
    pub metadata: serde_json::Value,
}

// =============================================================================
// List Response DTO
// =============================================================================

/// Paginated list response for PrintedCheck 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 PrintedCheckListResponseDto {
    /// List of items
    pub items: Vec<PrintedCheckResponseDto>,
    /// 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 PrintedCheckListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<PrintedCheckResponseDto>, 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 PrintedCheckSummaryDto {
    pub id: Uuid,
    pub bank_account_id: Uuid,
    pub payment_id: Uuid,
    pub payment_number: Option<String>,
    pub created_at: Option<DateTime<Utc>>,
}

// =============================================================================
// Conversions
// =============================================================================

impl From<PrintedCheck> for PrintedCheckResponseDto {
    fn from(entity: PrintedCheck) -> Self {
        Self {
            id: entity.id,
            bank_account_id: entity.bank_account_id,
            payment_id: entity.payment_id,
            payment_number: entity.payment_number,
            check_number: entity.check_number,
            amount: entity.amount,
            payee_name: entity.payee_name,
            status: entity.status,
            printed_at: entity.printed_at,
            printed_by: entity.printed_by,
            created_at: entity.created_at,
            updated_at: entity.updated_at,
            metadata: entity.metadata,
        }
    }
}

impl From<PrintedCheck> for PrintedCheckSummaryDto {
    fn from(entity: PrintedCheck) -> Self {
        Self {
            id: entity.id,
            bank_account_id: entity.bank_account_id,
            payment_id: entity.payment_id,
            payment_number: entity.payment_number,
            created_at: Some(entity.created_at),
        }
    }
}

impl From<CreatePrintedCheckDto> for PrintedCheck {
    fn from(dto: CreatePrintedCheckDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            bank_account_id: dto.bank_account_id,
            payment_id: dto.payment_id,
            payment_number: dto.payment_number,
            check_number: dto.check_number,
            amount: dto.amount,
            payee_name: dto.payee_name,
            status: dto.status,
            printed_at: dto.printed_at,
            printed_by: dto.printed_by,
            created_at: Utc::now(),
            updated_at: Utc::now(),
            metadata: serde_json::json!({}),
        }
    }
}

impl From<&PrintedCheck> for PrintedCheckResponseDto {
    fn from(entity: &PrintedCheck) -> Self {
        Self {
            id: entity.id.clone(),
            bank_account_id: entity.bank_account_id.clone(),
            payment_id: entity.payment_id.clone(),
            payment_number: entity.payment_number.clone(),
            check_number: entity.check_number.clone(),
            amount: entity.amount.clone(),
            payee_name: entity.payee_name.clone(),
            status: entity.status.clone(),
            printed_at: entity.printed_at.clone(),
            printed_by: entity.printed_by.clone(),
            created_at: entity.created_at.clone(),
            updated_at: entity.updated_at.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

impl backbone_core::FromCreateDto<CreatePrintedCheckDto> for PrintedCheck {
    fn from_create_dto(dto: CreatePrintedCheckDto) -> backbone_core::ServiceResult<Self> {
        Ok(PrintedCheck::from(dto))
    }
}

impl backbone_core::ApplyUpdateDto<UpdatePrintedCheckDto> for PrintedCheck {
    fn apply_update(mut self, dto: UpdatePrintedCheckDto) -> backbone_core::ServiceResult<Self> {
        self.updated_at = Utc::now();
        self.bank_account_id = dto.bank_account_id;
        self.payment_id = dto.payment_id;
        self.payment_number = dto.payment_number;
        self.check_number = dto.check_number;
        self.amount = dto.amount;
        self.payee_name = dto.payee_name;
        self.status = dto.status;
        self.printed_at = dto.printed_at;
        self.printed_by = dto.printed_by;
        Ok(self)
    }
}

// =============================================================================
// Custom DTOs
// =============================================================================

// Add custom DTOs specific to PrintedCheck here.
// This section will be preserved during regeneration.
// >>> END CUSTOM DTOs