//! AccountingPost 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::AccountingPost;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::PostingSourceType;
use crate::domain::entity::PostingStatus;
use crate::domain::entity::PostingType;
// =============================================================================
// Create DTO
// =============================================================================
/// Request DTO for creating a new AccountingPost
///
/// 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 CreateAccountingPostDto {
#[serde(default, skip_serializing_if = "Option::is_none", alias = "branch_id")]
pub branch_id: Option<Uuid>,
#[serde(alias = "source_type")]
pub source_type: PostingSourceType,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "source_id")]
pub source_id: Uuid,
#[cfg_attr(feature = "validation", validate(length(max = 100)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "source_reference")]
pub source_reference: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "journal_id")]
pub journal_id: Option<Uuid>,
#[serde(alias = "posting_type")]
pub posting_type: PostingType,
#[serde(alias = "posting_status")]
pub posting_status: PostingStatus,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub currency: String,
#[serde(alias = "total_debit")]
pub total_debit: Decimal,
#[serde(alias = "total_credit")]
pub total_credit: Decimal,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "scheduled_at")]
pub scheduled_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "posted_at")]
pub posted_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "failed_at")]
pub failed_at: Option<DateTime<Utc>>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "retry_count")]
pub retry_count: i32,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "max_retries")]
pub max_retries: i32,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "next_retry_at")]
pub next_retry_at: Option<DateTime<Utc>>,
#[cfg_attr(feature = "validation", validate(length(max = 50)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "error_code")]
pub error_code: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 1000)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "error_message")]
pub error_message: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "reverses_post_id")]
pub reverses_post_id: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "reversed_by_post_id")]
pub reversed_by_post_id: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "posted_by")]
pub posted_by: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 500)))]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
}
// =============================================================================
// Update DTO
// =============================================================================
/// Request DTO for full update of a AccountingPost
///
/// 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 UpdateAccountingPostDto {
#[serde(default, skip_serializing_if = "Option::is_none", alias = "branch_id")]
pub branch_id: Option<Uuid>,
#[serde(alias = "source_type")]
pub source_type: PostingSourceType,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(alias = "source_id")]
pub source_id: Uuid,
#[cfg_attr(feature = "validation", validate(length(max = 100)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "source_reference")]
pub source_reference: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "journal_id")]
pub journal_id: Option<Uuid>,
#[serde(alias = "posting_type")]
pub posting_type: PostingType,
#[serde(alias = "posting_status")]
pub posting_status: PostingStatus,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub currency: String,
#[serde(alias = "total_debit")]
pub total_debit: Decimal,
#[serde(alias = "total_credit")]
pub total_credit: Decimal,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "scheduled_at")]
pub scheduled_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "posted_at")]
pub posted_at: Option<DateTime<Utc>>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "failed_at")]
pub failed_at: Option<DateTime<Utc>>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "retry_count")]
pub retry_count: i32,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "max_retries")]
pub max_retries: i32,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "next_retry_at")]
pub next_retry_at: Option<DateTime<Utc>>,
#[cfg_attr(feature = "validation", validate(length(max = 50)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "error_code")]
pub error_code: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 1000)))]
#[serde(default, skip_serializing_if = "Option::is_none", alias = "error_message")]
pub error_message: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "reverses_post_id")]
pub reverses_post_id: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "reversed_by_post_id")]
pub reversed_by_post_id: Option<Uuid>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "posted_by")]
pub posted_by: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 500)))]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
}
// =============================================================================
// Patch DTO
// =============================================================================
/// Request DTO for partial update of a AccountingPost
///
/// 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 PatchAccountingPostDto {
#[serde(skip_serializing_if = "Option::is_none", alias = "branch_id")]
pub branch_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "source_type")]
pub source_type: Option<PostingSourceType>,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "source_id")]
pub source_id: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 100)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "source_reference")]
pub source_reference: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "journal_id")]
pub journal_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "posting_type")]
pub posting_type: Option<PostingType>,
#[serde(skip_serializing_if = "Option::is_none", alias = "posting_status")]
pub posting_status: Option<PostingStatus>,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "total_debit")]
pub total_debit: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "total_credit")]
pub total_credit: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "scheduled_at")]
pub scheduled_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none", alias = "posted_at")]
pub posted_at: Option<DateTime<Utc>>,
#[serde(skip_serializing_if = "Option::is_none", alias = "failed_at")]
pub failed_at: Option<DateTime<Utc>>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(skip_serializing_if = "Option::is_none", alias = "retry_count")]
pub retry_count: Option<i32>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(skip_serializing_if = "Option::is_none", alias = "max_retries")]
pub max_retries: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none", alias = "next_retry_at")]
pub next_retry_at: Option<DateTime<Utc>>,
#[cfg_attr(feature = "validation", validate(length(max = 50)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "error_code")]
pub error_code: Option<String>,
#[cfg_attr(feature = "validation", validate(length(max = 1000)))]
#[serde(skip_serializing_if = "Option::is_none", alias = "error_message")]
pub error_message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "reverses_post_id")]
pub reverses_post_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "reversed_by_post_id")]
pub reversed_by_post_id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none", alias = "posted_by")]
pub posted_by: Option<Uuid>,
#[cfg_attr(feature = "validation", validate(length(max = 500)))]
#[serde(skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
}
impl PatchAccountingPostDto {
/// Check if any field is set
pub fn has_changes(&self) -> bool {
self.branch_id.is_some() || self.source_type.is_some() || self.source_id.is_some() || self.source_reference.is_some() || self.journal_id.is_some() || self.posting_type.is_some() || self.posting_status.is_some() || self.currency.is_some() || self.total_debit.is_some() || self.total_credit.is_some() || self.scheduled_at.is_some() || self.posted_at.is_some() || self.failed_at.is_some() || self.retry_count.is_some() || self.max_retries.is_some() || self.next_retry_at.is_some() || self.error_code.is_some() || self.error_message.is_some() || self.reverses_post_id.is_some() || self.reversed_by_post_id.is_some() || self.posted_by.is_some() || self.notes.is_some()
}
}
// =============================================================================
// Response DTO
// =============================================================================
/// Response DTO for AccountingPost 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 AccountingPostResponseDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub id: Uuid,
pub branch_id: Option<Uuid>,
pub source_type: PostingSourceType,
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub source_id: Uuid,
pub source_reference: Option<String>,
pub journal_id: Option<Uuid>,
pub posting_type: PostingType,
pub posting_status: PostingStatus,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub currency: String,
pub total_debit: Decimal,
pub total_credit: Decimal,
pub scheduled_at: Option<DateTime<Utc>>,
pub posted_at: Option<DateTime<Utc>>,
pub failed_at: Option<DateTime<Utc>>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
pub retry_count: i32,
#[cfg_attr(feature = "openapi", schema(example = 42))]
pub max_retries: i32,
pub next_retry_at: Option<DateTime<Utc>>,
pub error_code: Option<String>,
pub error_message: Option<String>,
pub reverses_post_id: Option<Uuid>,
pub reversed_by_post_id: Option<Uuid>,
pub posted_by: Option<Uuid>,
pub notes: Option<String>,
pub metadata: AuditMetadata,
}
// =============================================================================
// List Response DTO
// =============================================================================
/// Paginated list response for AccountingPost 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 AccountingPostListResponseDto {
/// List of items
pub items: Vec<AccountingPostResponseDto>,
/// 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 AccountingPostListResponseDto {
/// Create a new list response from items and pagination info
pub fn new(items: Vec<AccountingPostResponseDto>, 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 AccountingPostSummaryDto {
pub id: Uuid,
pub branch_id: Option<Uuid>,
pub source_type: PostingSourceType,
pub source_id: Uuid,
pub created_at: Option<DateTime<Utc>>,
}
// =============================================================================
// Conversions
// =============================================================================
impl From<AccountingPost> for AccountingPostResponseDto {
fn from(entity: AccountingPost) -> Self {
Self {
id: entity.id,
branch_id: entity.branch_id,
source_type: entity.source_type,
source_id: entity.source_id,
source_reference: entity.source_reference,
journal_id: entity.journal_id,
posting_type: entity.posting_type,
posting_status: entity.posting_status,
currency: entity.currency,
total_debit: entity.total_debit,
total_credit: entity.total_credit,
scheduled_at: entity.scheduled_at,
posted_at: entity.posted_at,
failed_at: entity.failed_at,
retry_count: entity.retry_count,
max_retries: entity.max_retries,
next_retry_at: entity.next_retry_at,
error_code: entity.error_code,
error_message: entity.error_message,
reverses_post_id: entity.reverses_post_id,
reversed_by_post_id: entity.reversed_by_post_id,
posted_by: entity.posted_by,
notes: entity.notes,
metadata: entity.metadata,
}
}
}
impl From<AccountingPost> for AccountingPostSummaryDto {
fn from(entity: AccountingPost) -> Self {
let created_at = backbone_core::PersistentEntity::created_at(&entity);
Self {
id: entity.id,
branch_id: entity.branch_id,
source_type: entity.source_type,
source_id: entity.source_id,
created_at,
}
}
}
impl From<CreateAccountingPostDto> for AccountingPost {
fn from(dto: CreateAccountingPostDto) -> Self {
Self {
id: Uuid::new_v4(),
branch_id: dto.branch_id,
source_type: dto.source_type,
source_id: dto.source_id,
source_reference: dto.source_reference,
journal_id: dto.journal_id,
posting_type: dto.posting_type,
posting_status: dto.posting_status,
currency: dto.currency,
total_debit: dto.total_debit,
total_credit: dto.total_credit,
scheduled_at: dto.scheduled_at,
posted_at: dto.posted_at,
failed_at: dto.failed_at,
retry_count: dto.retry_count,
max_retries: dto.max_retries,
next_retry_at: dto.next_retry_at,
error_code: dto.error_code,
error_message: dto.error_message,
reverses_post_id: dto.reverses_post_id,
reversed_by_post_id: dto.reversed_by_post_id,
posted_by: dto.posted_by,
notes: dto.notes,
metadata: AuditMetadata::default(),
}
}
}
impl From<&AccountingPost> for AccountingPostResponseDto {
fn from(entity: &AccountingPost) -> Self {
Self {
id: entity.id.clone(),
branch_id: entity.branch_id.clone(),
source_type: entity.source_type.clone(),
source_id: entity.source_id.clone(),
source_reference: entity.source_reference.clone(),
journal_id: entity.journal_id.clone(),
posting_type: entity.posting_type.clone(),
posting_status: entity.posting_status.clone(),
currency: entity.currency.clone(),
total_debit: entity.total_debit.clone(),
total_credit: entity.total_credit.clone(),
scheduled_at: entity.scheduled_at.clone(),
posted_at: entity.posted_at.clone(),
failed_at: entity.failed_at.clone(),
retry_count: entity.retry_count.clone(),
max_retries: entity.max_retries.clone(),
next_retry_at: entity.next_retry_at.clone(),
error_code: entity.error_code.clone(),
error_message: entity.error_message.clone(),
reverses_post_id: entity.reverses_post_id.clone(),
reversed_by_post_id: entity.reversed_by_post_id.clone(),
posted_by: entity.posted_by.clone(),
notes: entity.notes.clone(),
metadata: entity.metadata.clone(),
}
}
}
impl backbone_core::FromCreateDto<CreateAccountingPostDto> for AccountingPost {
fn from_create_dto(dto: CreateAccountingPostDto) -> backbone_core::ServiceResult<Self> {
Ok(AccountingPost::from(dto))
}
}
impl backbone_core::ApplyUpdateDto<UpdateAccountingPostDto> for AccountingPost {
fn apply_update(mut self, dto: UpdateAccountingPostDto) -> backbone_core::ServiceResult<Self> {
self.branch_id = dto.branch_id;
self.source_type = dto.source_type;
self.source_id = dto.source_id;
self.source_reference = dto.source_reference;
self.journal_id = dto.journal_id;
self.posting_type = dto.posting_type;
self.posting_status = dto.posting_status;
self.currency = dto.currency;
self.total_debit = dto.total_debit;
self.total_credit = dto.total_credit;
self.scheduled_at = dto.scheduled_at;
self.posted_at = dto.posted_at;
self.failed_at = dto.failed_at;
self.retry_count = dto.retry_count;
self.max_retries = dto.max_retries;
self.next_retry_at = dto.next_retry_at;
self.error_code = dto.error_code;
self.error_message = dto.error_message;
self.reverses_post_id = dto.reverses_post_id;
self.reversed_by_post_id = dto.reversed_by_post_id;
self.posted_by = dto.posted_by;
self.notes = dto.notes;
Ok(self)
}
}
// =============================================================================
// Custom DTOs
// =============================================================================
// <<< CUSTOM DTOs
// Add custom DTOs specific to AccountingPost here.
// This section will be preserved during regeneration.
// >>> END CUSTOM DTOs