backbone-inventory 0.17.2

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

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

/// Request DTO for creating a new PickingBatch
///
/// 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 CreatePickingBatchDto {
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub name: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub note: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "is_wave")]
    pub is_wave: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "user_id")]
    pub user_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    #[serde(alias = "scheduled_date")]
    pub scheduled_date: DateTime<Utc>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "had_members")]
    pub had_members: bool,
}

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

/// Request DTO for full update of a PickingBatch
///
/// 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 UpdatePickingBatchDto {
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub name: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub note: Option<String>,
    pub state: PickingBatchState,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "is_wave")]
    pub is_wave: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "user_id")]
    pub user_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    #[serde(alias = "scheduled_date")]
    pub scheduled_date: DateTime<Utc>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "had_members")]
    pub had_members: bool,
}

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

/// Request DTO for partial update of a PickingBatch
///
/// 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 PatchPickingBatchDto {
    #[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 note: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub state: Option<PickingBatchState>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "is_wave")]
    pub is_wave: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "user_id")]
    pub user_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "scheduled_date")]
    pub scheduled_date: Option<DateTime<Utc>>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "had_members")]
    pub had_members: Option<bool>,
}

impl PatchPickingBatchDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.name.is_some() || self.note.is_some() || self.state.is_some() || self.is_wave.is_some() || self.user_id.is_some() || self.scheduled_date.is_some() || self.had_members.is_some()
    }
}

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

/// Response DTO for PickingBatch 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 PickingBatchResponseDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub name: String,
    pub note: Option<String>,
    pub state: PickingBatchState,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub is_wave: bool,
    pub user_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "2024-01-01T00:00:00Z"))]
    pub scheduled_date: DateTime<Utc>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub had_members: bool,
    pub metadata: AuditMetadata,
}

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

/// Paginated list response for PickingBatch 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 PickingBatchListResponseDto {
    /// List of items
    pub items: Vec<PickingBatchResponseDto>,
    /// 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 PickingBatchListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<PickingBatchResponseDto>, 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 PickingBatchSummaryDto {
    pub id: Uuid,
    pub name: String,
    pub note: Option<String>,
    pub state: PickingBatchState,
    pub created_at: Option<DateTime<Utc>>,
}

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

impl From<PickingBatch> for PickingBatchResponseDto {
    fn from(entity: PickingBatch) -> Self {
        Self {
            id: entity.id,
            name: entity.name,
            note: entity.note,
            state: entity.state,
            is_wave: entity.is_wave,
            user_id: entity.user_id,
            scheduled_date: entity.scheduled_date,
            had_members: entity.had_members,
            metadata: entity.metadata,
        }
    }
}

impl From<PickingBatch> for PickingBatchSummaryDto {
    fn from(entity: PickingBatch) -> Self {
        let created_at = backbone_core::PersistentEntity::created_at(&entity);
        Self {
            id: entity.id,
            name: entity.name,
            note: entity.note,
            state: entity.state,
            created_at,
        }
    }
}

impl From<CreatePickingBatchDto> for PickingBatch {
    fn from(dto: CreatePickingBatchDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            name: dto.name,
            note: dto.note,
            state: PickingBatchState::Draft,
            is_wave: dto.is_wave,
            user_id: dto.user_id,
            scheduled_date: dto.scheduled_date,
            had_members: dto.had_members,
            metadata: AuditMetadata::default(),
        }
    }
}

impl From<&PickingBatch> for PickingBatchResponseDto {
    fn from(entity: &PickingBatch) -> Self {
        Self {
            id: entity.id.clone(),
            name: entity.name.clone(),
            note: entity.note.clone(),
            state: entity.state.clone(),
            is_wave: entity.is_wave.clone(),
            user_id: entity.user_id.clone(),
            scheduled_date: entity.scheduled_date.clone(),
            had_members: entity.had_members.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

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

impl backbone_core::ApplyUpdateDto<UpdatePickingBatchDto> for PickingBatch {
    fn apply_update(mut self, dto: UpdatePickingBatchDto) -> backbone_core::ServiceResult<Self> {
        self.name = dto.name;
        self.note = dto.note;
        self.state = dto.state;
        self.is_wave = dto.is_wave;
        self.user_id = dto.user_id;
        self.scheduled_date = dto.scheduled_date;
        self.had_members = dto.had_members;
        Ok(self)
    }
}

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

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