backbone-inventory 0.17.2

Inventory: stock ledger of record (SLE) + moving-average valuation; emits COGS/asset AccountingPost (Delivery/Receipt -> GL)
Documentation
//! LandedCostAdjustmentLine 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::LandedCostAdjustmentLine;
use crate::domain::entity::AuditMetadata;

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

/// Request DTO for creating a new LandedCostAdjustmentLine
///
/// 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 CreateLandedCostAdjustmentLineDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "lc_id")]
    pub lc_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "move_line_id")]
    pub move_line_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "cost_line_id")]
    pub cost_line_id: Uuid,
    pub share: Decimal,
    #[serde(alias = "additional_landed_cost")]
    pub additional_landed_cost: Decimal,
    #[serde(alias = "remaining_qty")]
    pub remaining_qty: Decimal,
}

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

/// Request DTO for full update of a LandedCostAdjustmentLine
///
/// 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 UpdateLandedCostAdjustmentLineDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "lc_id")]
    pub lc_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "move_line_id")]
    pub move_line_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "cost_line_id")]
    pub cost_line_id: Uuid,
    pub share: Decimal,
    #[serde(alias = "additional_landed_cost")]
    pub additional_landed_cost: Decimal,
    #[serde(alias = "remaining_qty")]
    pub remaining_qty: Decimal,
}

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

/// Request DTO for partial update of a LandedCostAdjustmentLine
///
/// 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 PatchLandedCostAdjustmentLineDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "lc_id")]
    pub lc_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "move_line_id")]
    pub move_line_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "cost_line_id")]
    pub cost_line_id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub share: Option<Decimal>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "additional_landed_cost")]
    pub additional_landed_cost: Option<Decimal>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "remaining_qty")]
    pub remaining_qty: Option<Decimal>,
}

impl PatchLandedCostAdjustmentLineDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.lc_id.is_some() || self.move_line_id.is_some() || self.cost_line_id.is_some() || self.share.is_some() || self.additional_landed_cost.is_some() || self.remaining_qty.is_some()
    }
}

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

/// Response DTO for LandedCostAdjustmentLine 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 LandedCostAdjustmentLineResponseDto {
    #[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 lc_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub move_line_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub cost_line_id: Uuid,
    pub share: Decimal,
    pub additional_landed_cost: Decimal,
    pub remaining_qty: Decimal,
    pub metadata: AuditMetadata,
}

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

/// Paginated list response for LandedCostAdjustmentLine 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 LandedCostAdjustmentLineListResponseDto {
    /// List of items
    pub items: Vec<LandedCostAdjustmentLineResponseDto>,
    /// 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 LandedCostAdjustmentLineListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<LandedCostAdjustmentLineResponseDto>, 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 LandedCostAdjustmentLineSummaryDto {
    pub id: Uuid,
    pub lc_id: Uuid,
    pub move_line_id: Uuid,
    pub cost_line_id: Uuid,
    pub created_at: Option<DateTime<Utc>>,
}

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

impl From<LandedCostAdjustmentLine> for LandedCostAdjustmentLineResponseDto {
    fn from(entity: LandedCostAdjustmentLine) -> Self {
        Self {
            id: entity.id,
            lc_id: entity.lc_id,
            move_line_id: entity.move_line_id,
            cost_line_id: entity.cost_line_id,
            share: entity.share,
            additional_landed_cost: entity.additional_landed_cost,
            remaining_qty: entity.remaining_qty,
            metadata: entity.metadata,
        }
    }
}

impl From<LandedCostAdjustmentLine> for LandedCostAdjustmentLineSummaryDto {
    fn from(entity: LandedCostAdjustmentLine) -> Self {
        let created_at = backbone_core::PersistentEntity::created_at(&entity);
        Self {
            id: entity.id,
            lc_id: entity.lc_id,
            move_line_id: entity.move_line_id,
            cost_line_id: entity.cost_line_id,
            created_at,
        }
    }
}

impl From<CreateLandedCostAdjustmentLineDto> for LandedCostAdjustmentLine {
    fn from(dto: CreateLandedCostAdjustmentLineDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            lc_id: dto.lc_id,
            move_line_id: dto.move_line_id,
            cost_line_id: dto.cost_line_id,
            share: dto.share,
            additional_landed_cost: dto.additional_landed_cost,
            remaining_qty: dto.remaining_qty,
            metadata: AuditMetadata::default(),
        }
    }
}

impl From<&LandedCostAdjustmentLine> for LandedCostAdjustmentLineResponseDto {
    fn from(entity: &LandedCostAdjustmentLine) -> Self {
        Self {
            id: entity.id.clone(),
            lc_id: entity.lc_id.clone(),
            move_line_id: entity.move_line_id.clone(),
            cost_line_id: entity.cost_line_id.clone(),
            share: entity.share.clone(),
            additional_landed_cost: entity.additional_landed_cost.clone(),
            remaining_qty: entity.remaining_qty.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

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

impl backbone_core::ApplyUpdateDto<UpdateLandedCostAdjustmentLineDto> for LandedCostAdjustmentLine {
    fn apply_update(mut self, dto: UpdateLandedCostAdjustmentLineDto) -> backbone_core::ServiceResult<Self> {
        self.lc_id = dto.lc_id;
        self.move_line_id = dto.move_line_id;
        self.cost_line_id = dto.cost_line_id;
        self.share = dto.share;
        self.additional_landed_cost = dto.additional_landed_cost;
        self.remaining_qty = dto.remaining_qty;
        Ok(self)
    }
}

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

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