backbone-inventory 0.17.2

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

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

/// Request DTO for creating a new InventoryCompanySetting
///
/// 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 CreateInventoryCompanySettingDto {
    #[serde(alias = "cost_method")]
    pub cost_method: InventoryCostMethod,
    #[serde(alias = "valuation_policy")]
    pub valuation_policy: ValuationPolicy,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "anglo_saxon_accounting")]
    pub anglo_saxon_accounting: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "stock_interim_delivered_account_id")]
    pub stock_interim_delivered_account_id: Option<Uuid>,
}

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

/// Request DTO for full update of a InventoryCompanySetting
///
/// 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 UpdateInventoryCompanySettingDto {
    #[serde(alias = "cost_method")]
    pub cost_method: InventoryCostMethod,
    #[serde(alias = "valuation_policy")]
    pub valuation_policy: ValuationPolicy,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "anglo_saxon_accounting")]
    pub anglo_saxon_accounting: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "stock_interim_delivered_account_id")]
    pub stock_interim_delivered_account_id: Option<Uuid>,
}

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

/// Request DTO for partial update of a InventoryCompanySetting
///
/// 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 PatchInventoryCompanySettingDto {
    #[serde(skip_serializing_if = "Option::is_none", alias = "cost_method")]
    pub cost_method: Option<InventoryCostMethod>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "valuation_policy")]
    pub valuation_policy: Option<ValuationPolicy>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "anglo_saxon_accounting")]
    pub anglo_saxon_accounting: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "stock_interim_delivered_account_id")]
    pub stock_interim_delivered_account_id: Option<Uuid>,
}

impl PatchInventoryCompanySettingDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.cost_method.is_some() || self.valuation_policy.is_some() || self.anglo_saxon_accounting.is_some() || self.stock_interim_delivered_account_id.is_some()
    }
}

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

/// Response DTO for InventoryCompanySetting 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 InventoryCompanySettingResponseDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub id: Uuid,
    pub cost_method: InventoryCostMethod,
    pub valuation_policy: ValuationPolicy,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub anglo_saxon_accounting: bool,
    pub stock_interim_delivered_account_id: Option<Uuid>,
    pub metadata: AuditMetadata,
}

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

/// Paginated list response for InventoryCompanySetting 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 InventoryCompanySettingListResponseDto {
    /// List of items
    pub items: Vec<InventoryCompanySettingResponseDto>,
    /// 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 InventoryCompanySettingListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<InventoryCompanySettingResponseDto>, 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 InventoryCompanySettingSummaryDto {
    pub id: Uuid,
    pub cost_method: InventoryCostMethod,
    pub valuation_policy: ValuationPolicy,
    pub anglo_saxon_accounting: bool,
    pub created_at: Option<DateTime<Utc>>,
}

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

impl From<InventoryCompanySetting> for InventoryCompanySettingResponseDto {
    fn from(entity: InventoryCompanySetting) -> Self {
        Self {
            id: entity.id,
            cost_method: entity.cost_method,
            valuation_policy: entity.valuation_policy,
            anglo_saxon_accounting: entity.anglo_saxon_accounting,
            stock_interim_delivered_account_id: entity.stock_interim_delivered_account_id,
            metadata: entity.metadata,
        }
    }
}

impl From<InventoryCompanySetting> for InventoryCompanySettingSummaryDto {
    fn from(entity: InventoryCompanySetting) -> Self {
        let created_at = backbone_core::PersistentEntity::created_at(&entity);
        Self {
            id: entity.id,
            cost_method: entity.cost_method,
            valuation_policy: entity.valuation_policy,
            anglo_saxon_accounting: entity.anglo_saxon_accounting,
            created_at,
        }
    }
}

impl From<CreateInventoryCompanySettingDto> for InventoryCompanySetting {
    fn from(dto: CreateInventoryCompanySettingDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            cost_method: dto.cost_method,
            valuation_policy: dto.valuation_policy,
            anglo_saxon_accounting: dto.anglo_saxon_accounting,
            stock_interim_delivered_account_id: dto.stock_interim_delivered_account_id,
            metadata: AuditMetadata::default(),
        }
    }
}

impl From<&InventoryCompanySetting> for InventoryCompanySettingResponseDto {
    fn from(entity: &InventoryCompanySetting) -> Self {
        Self {
            id: entity.id.clone(),
            cost_method: entity.cost_method.clone(),
            valuation_policy: entity.valuation_policy.clone(),
            anglo_saxon_accounting: entity.anglo_saxon_accounting.clone(),
            stock_interim_delivered_account_id: entity.stock_interim_delivered_account_id.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

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

impl backbone_core::ApplyUpdateDto<UpdateInventoryCompanySettingDto> for InventoryCompanySetting {
    fn apply_update(mut self, dto: UpdateInventoryCompanySettingDto) -> backbone_core::ServiceResult<Self> {
        self.cost_method = dto.cost_method;
        self.valuation_policy = dto.valuation_policy;
        self.anglo_saxon_accounting = dto.anglo_saxon_accounting;
        self.stock_interim_delivered_account_id = dto.stock_interim_delivered_account_id;
        Ok(self)
    }
}

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

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