//! Account 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, NaiveDate};
use rust_decimal::Decimal;
#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
use crate::domain::entity::Account;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::AccountStatus;
use crate::domain::entity::AccountSubtype;
use crate::domain::entity::AccountType;
use crate::domain::entity::NormalBalance;
// =============================================================================
// Create DTO
// =============================================================================
/// Request DTO for creating a new Account
///
/// 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 CreateAccountDto {
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "account_number")]
pub account_number: String,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "account_code")]
pub account_code: String,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(alias = "account_type")]
pub account_type: AccountType,
#[serde(alias = "account_subtype")]
pub account_subtype: AccountSubtype,
#[serde(alias = "normal_balance")]
pub normal_balance: NormalBalance,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "parent_id")]
pub parent_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
pub level: i32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_header")]
pub is_header: bool,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_detail")]
pub is_detail: bool,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub currency: String,
#[serde(alias = "opening_balance")]
pub opening_balance: Decimal,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "opening_balance_date")]
pub opening_balance_date: Option<NaiveDate>,
#[serde(alias = "current_balance")]
pub current_balance: Decimal,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_reconcilable")]
pub is_reconcilable: bool,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "has_budget")]
pub has_budget: bool,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "budget_amount")]
pub budget_amount: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "sort_order")]
pub sort_order: i32,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "show_in_reports")]
pub show_in_reports: bool,
pub status: AccountStatus,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_system")]
pub is_system: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "source_id")]
pub source_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_cloned")]
pub is_cloned: bool,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "chart_code")]
pub chart_code: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "chart_version")]
pub chart_version: Option<String>,
}
// =============================================================================
// Update DTO
// =============================================================================
/// Request DTO for full update of a Account
///
/// 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 UpdateAccountDto {
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "account_number")]
pub account_number: String,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(alias = "account_code")]
pub account_code: String,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(alias = "account_type")]
pub account_type: AccountType,
#[serde(alias = "account_subtype")]
pub account_subtype: AccountSubtype,
#[serde(alias = "normal_balance")]
pub normal_balance: NormalBalance,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "parent_id")]
pub parent_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
pub level: i32,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_header")]
pub is_header: bool,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_detail")]
pub is_detail: bool,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub currency: String,
#[serde(alias = "opening_balance")]
pub opening_balance: Decimal,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "opening_balance_date")]
pub opening_balance_date: Option<NaiveDate>,
#[serde(alias = "current_balance")]
pub current_balance: Decimal,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_reconcilable")]
pub is_reconcilable: bool,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "has_budget")]
pub has_budget: bool,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "budget_amount")]
pub budget_amount: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(alias = "sort_order")]
pub sort_order: i32,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "show_in_reports")]
pub show_in_reports: bool,
pub status: AccountStatus,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_system")]
pub is_system: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "source_id")]
pub source_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(alias = "is_cloned")]
pub is_cloned: bool,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "chart_code")]
pub chart_code: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none", alias = "chart_version")]
pub chart_version: Option<String>,
}
// =============================================================================
// Patch DTO
// =============================================================================
/// Request DTO for partial update of a Account
///
/// 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 PatchAccountDto {
#[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 = "openapi", schema(example = "example"))]
#[serde(skip_serializing_if = "Option::is_none", alias = "account_code")]
pub account_code: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "account_type")]
pub account_type: Option<AccountType>,
#[serde(skip_serializing_if = "Option::is_none", alias = "account_subtype")]
pub account_subtype: Option<AccountSubtype>,
#[serde(skip_serializing_if = "Option::is_none", alias = "normal_balance")]
pub normal_balance: Option<NormalBalance>,
#[serde(skip_serializing_if = "Option::is_none", alias = "parent_id")]
pub parent_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(skip_serializing_if = "Option::is_none")]
pub level: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub path: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "is_header")]
pub is_header: Option<bool>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "is_detail")]
pub is_detail: Option<bool>,
#[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 = "opening_balance")]
pub opening_balance: Option<Decimal>,
#[serde(skip_serializing_if = "Option::is_none", alias = "opening_balance_date")]
pub opening_balance_date: Option<NaiveDate>,
#[serde(skip_serializing_if = "Option::is_none", alias = "current_balance")]
pub current_balance: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "is_reconcilable")]
pub is_reconcilable: Option<bool>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "has_budget")]
pub has_budget: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none", alias = "budget_amount")]
pub budget_amount: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
#[serde(skip_serializing_if = "Option::is_none", alias = "sort_order")]
pub sort_order: Option<i32>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "show_in_reports")]
pub show_in_reports: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<AccountStatus>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "is_system")]
pub is_system: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub notes: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "source_id")]
pub source_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
#[serde(skip_serializing_if = "Option::is_none", alias = "is_cloned")]
pub is_cloned: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none", alias = "chart_code")]
pub chart_code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", alias = "chart_version")]
pub chart_version: Option<String>,
}
impl PatchAccountDto {
/// Check if any field is set
pub fn has_changes(&self) -> bool {
self.account_number.is_some() || self.account_code.is_some() || self.name.is_some() || self.description.is_some() || self.account_type.is_some() || self.account_subtype.is_some() || self.normal_balance.is_some() || self.parent_id.is_some() || self.level.is_some() || self.path.is_some() || self.is_header.is_some() || self.is_detail.is_some() || self.currency.is_some() || self.opening_balance.is_some() || self.opening_balance_date.is_some() || self.current_balance.is_some() || self.is_reconcilable.is_some() || self.has_budget.is_some() || self.budget_amount.is_some() || self.sort_order.is_some() || self.show_in_reports.is_some() || self.status.is_some() || self.is_system.is_some() || self.notes.is_some() || self.source_id.is_some() || self.is_cloned.is_some() || self.chart_code.is_some() || self.chart_version.is_some()
}
}
// =============================================================================
// Response DTO
// =============================================================================
/// Response DTO for Account 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 AccountResponseDto {
#[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
pub id: Uuid,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub account_number: String,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub account_code: String,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub name: String,
pub description: Option<String>,
pub account_type: AccountType,
pub account_subtype: AccountSubtype,
pub normal_balance: NormalBalance,
pub parent_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
pub level: i32,
pub path: Option<String>,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub is_header: bool,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub is_detail: bool,
#[cfg_attr(feature = "openapi", schema(example = "example"))]
pub currency: String,
pub opening_balance: Decimal,
pub opening_balance_date: Option<NaiveDate>,
pub current_balance: Decimal,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub is_reconcilable: bool,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub has_budget: bool,
pub budget_amount: Option<Decimal>,
#[cfg_attr(feature = "openapi", schema(example = 42))]
pub sort_order: i32,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub show_in_reports: bool,
pub status: AccountStatus,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub is_system: bool,
pub notes: Option<String>,
pub source_id: Option<Uuid>,
#[cfg_attr(feature = "openapi", schema(example = true))]
pub is_cloned: bool,
pub chart_code: Option<String>,
pub chart_version: Option<String>,
pub metadata: AuditMetadata,
}
// =============================================================================
// List Response DTO
// =============================================================================
/// Paginated list response for Account 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 AccountListResponseDto {
/// List of items
pub items: Vec<AccountResponseDto>,
/// 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 AccountListResponseDto {
/// Create a new list response from items and pagination info
pub fn new(items: Vec<AccountResponseDto>, 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 AccountSummaryDto {
pub id: Uuid,
pub account_number: String,
pub account_code: String,
pub name: String,
pub created_at: Option<DateTime<Utc>>,
}
// =============================================================================
// Conversions
// =============================================================================
impl From<Account> for AccountResponseDto {
fn from(entity: Account) -> Self {
Self {
id: entity.id,
account_number: entity.account_number,
account_code: entity.account_code,
name: entity.name,
description: entity.description,
account_type: entity.account_type,
account_subtype: entity.account_subtype,
normal_balance: entity.normal_balance,
parent_id: entity.parent_id,
level: entity.level,
path: entity.path,
is_header: entity.is_header,
is_detail: entity.is_detail,
currency: entity.currency,
opening_balance: entity.opening_balance,
opening_balance_date: entity.opening_balance_date,
current_balance: entity.current_balance,
is_reconcilable: entity.is_reconcilable,
has_budget: entity.has_budget,
budget_amount: entity.budget_amount,
sort_order: entity.sort_order,
show_in_reports: entity.show_in_reports,
status: entity.status,
is_system: entity.is_system,
notes: entity.notes,
source_id: entity.source_id,
is_cloned: entity.is_cloned,
chart_code: entity.chart_code,
chart_version: entity.chart_version,
metadata: entity.metadata,
}
}
}
impl From<Account> for AccountSummaryDto {
fn from(entity: Account) -> Self {
let created_at = backbone_core::PersistentEntity::created_at(&entity);
Self {
id: entity.id,
account_number: entity.account_number,
account_code: entity.account_code,
name: entity.name,
created_at,
}
}
}
impl From<CreateAccountDto> for Account {
fn from(dto: CreateAccountDto) -> Self {
Self {
id: Uuid::new_v4(),
account_number: dto.account_number,
account_code: dto.account_code,
name: dto.name,
description: dto.description,
account_type: dto.account_type,
account_subtype: dto.account_subtype,
normal_balance: dto.normal_balance,
parent_id: dto.parent_id,
level: dto.level,
path: dto.path,
is_header: dto.is_header,
is_detail: dto.is_detail,
currency: dto.currency,
opening_balance: dto.opening_balance,
opening_balance_date: dto.opening_balance_date,
current_balance: dto.current_balance,
is_reconcilable: dto.is_reconcilable,
has_budget: dto.has_budget,
budget_amount: dto.budget_amount,
sort_order: dto.sort_order,
show_in_reports: dto.show_in_reports,
status: dto.status,
is_system: dto.is_system,
notes: dto.notes,
source_id: dto.source_id,
is_cloned: dto.is_cloned,
chart_code: dto.chart_code,
chart_version: dto.chart_version,
metadata: AuditMetadata::default(),
}
}
}
impl From<&Account> for AccountResponseDto {
fn from(entity: &Account) -> Self {
Self {
id: entity.id.clone(),
account_number: entity.account_number.clone(),
account_code: entity.account_code.clone(),
name: entity.name.clone(),
description: entity.description.clone(),
account_type: entity.account_type.clone(),
account_subtype: entity.account_subtype.clone(),
normal_balance: entity.normal_balance.clone(),
parent_id: entity.parent_id.clone(),
level: entity.level.clone(),
path: entity.path.clone(),
is_header: entity.is_header.clone(),
is_detail: entity.is_detail.clone(),
currency: entity.currency.clone(),
opening_balance: entity.opening_balance.clone(),
opening_balance_date: entity.opening_balance_date.clone(),
current_balance: entity.current_balance.clone(),
is_reconcilable: entity.is_reconcilable.clone(),
has_budget: entity.has_budget.clone(),
budget_amount: entity.budget_amount.clone(),
sort_order: entity.sort_order.clone(),
show_in_reports: entity.show_in_reports.clone(),
status: entity.status.clone(),
is_system: entity.is_system.clone(),
notes: entity.notes.clone(),
source_id: entity.source_id.clone(),
is_cloned: entity.is_cloned.clone(),
chart_code: entity.chart_code.clone(),
chart_version: entity.chart_version.clone(),
metadata: entity.metadata.clone(),
}
}
}
impl backbone_core::FromCreateDto<CreateAccountDto> for Account {
fn from_create_dto(dto: CreateAccountDto) -> backbone_core::ServiceResult<Self> {
Ok(Account::from(dto))
}
}
impl backbone_core::ApplyUpdateDto<UpdateAccountDto> for Account {
fn apply_update(mut self, dto: UpdateAccountDto) -> backbone_core::ServiceResult<Self> {
self.account_number = dto.account_number;
self.account_code = dto.account_code;
self.name = dto.name;
self.description = dto.description;
self.account_type = dto.account_type;
self.account_subtype = dto.account_subtype;
self.normal_balance = dto.normal_balance;
self.parent_id = dto.parent_id;
self.level = dto.level;
self.path = dto.path;
self.is_header = dto.is_header;
self.is_detail = dto.is_detail;
self.currency = dto.currency;
self.opening_balance = dto.opening_balance;
self.opening_balance_date = dto.opening_balance_date;
self.current_balance = dto.current_balance;
self.is_reconcilable = dto.is_reconcilable;
self.has_budget = dto.has_budget;
self.budget_amount = dto.budget_amount;
self.sort_order = dto.sort_order;
self.show_in_reports = dto.show_in_reports;
self.status = dto.status;
self.is_system = dto.is_system;
self.notes = dto.notes;
self.source_id = dto.source_id;
self.is_cloned = dto.is_cloned;
self.chart_code = dto.chart_code;
self.chart_version = dto.chart_version;
Ok(self)
}
}
// =============================================================================
// Custom DTOs
// =============================================================================
// Add custom DTOs specific to Account here.
// This section will be preserved during regeneration.
// >>> END CUSTOM DTOs