backbone-banking 0.7.1

Cash & bank — bank/account master, statement import, reconciliation, and clearing postings (5th GL producer)
Documentation
//! ReconcilePreset 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};
use rust_decimal::Decimal;

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

#[cfg(feature = "validation")]
use validator::Validate;

use crate::domain::entity::ReconcilePreset;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::MatchOn;
use crate::domain::entity::PresetStatus;

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

/// Request DTO for creating a new ReconcilePreset
///
/// 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 CreateReconcilePresetDto {
    #[cfg_attr(feature = "validation", validate(length(max = 80)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub name: String,
    #[cfg_attr(feature = "validation", validate(length(max = 255)))]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub note: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub priority: i32,
    #[serde(alias = "match_on")]
    pub match_on: MatchOn,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "tolerance_percent")]
    pub tolerance_percent: Option<Decimal>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "days_window")]
    pub days_window: Option<i32>,
    pub status: PresetStatus,
}

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

/// Request DTO for full update of a ReconcilePreset
///
/// 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 UpdateReconcilePresetDto {
    #[cfg_attr(feature = "validation", validate(length(max = 80)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub name: String,
    #[cfg_attr(feature = "validation", validate(length(max = 255)))]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub note: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub priority: i32,
    #[serde(alias = "match_on")]
    pub match_on: MatchOn,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "tolerance_percent")]
    pub tolerance_percent: Option<Decimal>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "days_window")]
    pub days_window: Option<i32>,
    pub status: PresetStatus,
}

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

/// Request DTO for partial update of a ReconcilePreset
///
/// 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 PatchReconcilePresetDto {
    #[cfg_attr(feature = "validation", validate(length(max = 80)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[cfg_attr(feature = "validation", validate(length(max = 255)))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub note: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub priority: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "match_on")]
    pub match_on: Option<MatchOn>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "tolerance_percent")]
    pub tolerance_percent: Option<Decimal>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "days_window")]
    pub days_window: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<PresetStatus>,
}

impl PatchReconcilePresetDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.name.is_some() || self.note.is_some() || self.priority.is_some() || self.match_on.is_some() || self.tolerance_percent.is_some() || self.days_window.is_some() || self.status.is_some()
    }
}

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

/// Response DTO for ReconcilePreset 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 ReconcilePresetResponseDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub name: String,
    pub note: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub priority: i32,
    pub match_on: MatchOn,
    pub tolerance_percent: Option<Decimal>,
    pub days_window: Option<i32>,
    pub status: PresetStatus,
    pub metadata: AuditMetadata,
}

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

/// Paginated list response for ReconcilePreset 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 ReconcilePresetListResponseDto {
    /// List of items
    pub items: Vec<ReconcilePresetResponseDto>,
    /// 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 ReconcilePresetListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<ReconcilePresetResponseDto>, 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 ReconcilePresetSummaryDto {
    pub id: Uuid,
    pub name: String,
    pub note: Option<String>,
    pub priority: i32,
    pub created_at: Option<DateTime<Utc>>,
}

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

impl From<ReconcilePreset> for ReconcilePresetResponseDto {
    fn from(entity: ReconcilePreset) -> Self {
        Self {
            id: entity.id,
            name: entity.name,
            note: entity.note,
            priority: entity.priority,
            match_on: entity.match_on,
            tolerance_percent: entity.tolerance_percent,
            days_window: entity.days_window,
            status: entity.status,
            metadata: entity.metadata,
        }
    }
}

impl From<ReconcilePreset> for ReconcilePresetSummaryDto {
    fn from(entity: ReconcilePreset) -> Self {
        let created_at = backbone_core::PersistentEntity::created_at(&entity);
        Self {
            id: entity.id,
            name: entity.name,
            note: entity.note,
            priority: entity.priority,
            created_at,
        }
    }
}

impl From<CreateReconcilePresetDto> for ReconcilePreset {
    fn from(dto: CreateReconcilePresetDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            name: dto.name,
            note: dto.note,
            priority: dto.priority,
            match_on: dto.match_on,
            tolerance_percent: dto.tolerance_percent,
            days_window: dto.days_window,
            status: dto.status,
            metadata: AuditMetadata::default(),
        }
    }
}

impl From<&ReconcilePreset> for ReconcilePresetResponseDto {
    fn from(entity: &ReconcilePreset) -> Self {
        Self {
            id: entity.id.clone(),
            name: entity.name.clone(),
            note: entity.note.clone(),
            priority: entity.priority.clone(),
            match_on: entity.match_on.clone(),
            tolerance_percent: entity.tolerance_percent.clone(),
            days_window: entity.days_window.clone(),
            status: entity.status.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

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

impl backbone_core::ApplyUpdateDto<UpdateReconcilePresetDto> for ReconcilePreset {
    fn apply_update(mut self, dto: UpdateReconcilePresetDto) -> backbone_core::ServiceResult<Self> {
        self.name = dto.name;
        self.note = dto.note;
        self.priority = dto.priority;
        self.match_on = dto.match_on;
        self.tolerance_percent = dto.tolerance_percent;
        self.days_window = dto.days_window;
        self.status = dto.status;
        Ok(self)
    }
}

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

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