backbone-accounting 0.18.0

GL, journals, ledger, reconciliation (extracted from bersihir)
Documentation
//! BankCheckSequence 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};

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

use crate::domain::entity::BankCheckSequence;

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

/// Request DTO for creating a new BankCheckSequence
///
/// 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 CreateBankCheckSequenceDto {
    #[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 = "example"))]
    #[serde(alias = "numbering_mode")]
    pub numbering_mode: String,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(alias = "next_number")]
    pub next_number: i64,
}

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

/// Request DTO for full update of a BankCheckSequence
///
/// 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 UpdateBankCheckSequenceDto {
    #[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 = "example"))]
    #[serde(alias = "numbering_mode")]
    pub numbering_mode: String,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(alias = "next_number")]
    pub next_number: i64,
}

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

/// Request DTO for partial update of a BankCheckSequence
///
/// 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 PatchBankCheckSequenceDto {
    #[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 = "example"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "numbering_mode")]
    pub numbering_mode: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "next_number")]
    pub next_number: Option<i64>,
}

impl PatchBankCheckSequenceDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.bank_account_id.is_some() || self.numbering_mode.is_some() || self.next_number.is_some()
    }
}

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

/// Response DTO for BankCheckSequence 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 BankCheckSequenceResponseDto {
    #[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 = "example"))]
    pub numbering_mode: String,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub next_number: i64,
    #[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 BankCheckSequence 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 BankCheckSequenceListResponseDto {
    /// List of items
    pub items: Vec<BankCheckSequenceResponseDto>,
    /// 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 BankCheckSequenceListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<BankCheckSequenceResponseDto>, 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 BankCheckSequenceSummaryDto {
    pub id: Uuid,
    pub bank_account_id: Uuid,
    pub numbering_mode: String,
    pub next_number: i64,
    pub created_at: Option<DateTime<Utc>>,
}

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

impl From<BankCheckSequence> for BankCheckSequenceResponseDto {
    fn from(entity: BankCheckSequence) -> Self {
        Self {
            id: entity.id,
            bank_account_id: entity.bank_account_id,
            numbering_mode: entity.numbering_mode,
            next_number: entity.next_number,
            created_at: entity.created_at,
            updated_at: entity.updated_at,
            metadata: entity.metadata,
        }
    }
}

impl From<BankCheckSequence> for BankCheckSequenceSummaryDto {
    fn from(entity: BankCheckSequence) -> Self {
        Self {
            id: entity.id,
            bank_account_id: entity.bank_account_id,
            numbering_mode: entity.numbering_mode,
            next_number: entity.next_number,
            created_at: Some(entity.created_at),
        }
    }
}

impl From<CreateBankCheckSequenceDto> for BankCheckSequence {
    fn from(dto: CreateBankCheckSequenceDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            bank_account_id: dto.bank_account_id,
            numbering_mode: dto.numbering_mode,
            next_number: dto.next_number,
            created_at: Utc::now(),
            updated_at: Utc::now(),
            metadata: serde_json::json!({}),
        }
    }
}

impl From<&BankCheckSequence> for BankCheckSequenceResponseDto {
    fn from(entity: &BankCheckSequence) -> Self {
        Self {
            id: entity.id.clone(),
            bank_account_id: entity.bank_account_id.clone(),
            numbering_mode: entity.numbering_mode.clone(),
            next_number: entity.next_number.clone(),
            created_at: entity.created_at.clone(),
            updated_at: entity.updated_at.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

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

impl backbone_core::ApplyUpdateDto<UpdateBankCheckSequenceDto> for BankCheckSequence {
    fn apply_update(mut self, dto: UpdateBankCheckSequenceDto) -> backbone_core::ServiceResult<Self> {
        self.updated_at = Utc::now();
        self.bank_account_id = dto.bank_account_id;
        self.numbering_mode = dto.numbering_mode;
        self.next_number = dto.next_number;
        Ok(self)
    }
}

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

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