Skip to main content

backbone_support/presentation/dto/
service_level_agreement_dto.rs

1//! ServiceLevelAgreement DTOs (Data Transfer Objects)
2//!
3//! Generated by metaphor-schema. Do not edit manually.
4//!
5//! DTOs provide a clean separation between domain entities and API
6//! representations, with OpenAPI documentation support.
7
8use serde::{Deserialize, Serialize};
9use uuid::Uuid;
10use chrono::{DateTime, Utc};
11
12#[cfg(feature = "openapi")]
13#[cfg(feature = "openapi")]
14use utoipa::ToSchema;
15
16use crate::domain::entity::ServiceLevelAgreement;
17use crate::domain::entity::AuditMetadata;
18use crate::domain::entity::ServiceLevelAgreementStatus;
19
20// =============================================================================
21// Create DTO
22// =============================================================================
23
24/// Request DTO for creating a new ServiceLevelAgreement
25///
26/// Used in POST requests to create new entities.
27/// Excludes auto-generated fields (id, created_at, updated_at, deleted_at).
28#[derive(Debug, Clone, Deserialize)]
29#[cfg_attr(feature = "openapi", derive(ToSchema))]
30#[serde(rename_all = "camelCase")]
31pub struct CreateServiceLevelAgreementDto {
32    #[cfg_attr(feature = "openapi", schema(example = "example"))]
33    pub name: String,
34    #[cfg_attr(feature = "openapi", schema(example = true))]
35    #[serde(alias = "is_default")]
36    pub is_default: bool,
37    pub status: ServiceLevelAgreementStatus,
38}
39
40// =============================================================================
41// Update DTO
42// =============================================================================
43
44/// Request DTO for full update of a ServiceLevelAgreement
45///
46/// Used in PUT requests for full entity replacement.
47/// All fields are required (except auto-generated ones).
48#[derive(Debug, Clone, Deserialize)]
49#[cfg_attr(feature = "openapi", derive(ToSchema))]
50#[serde(rename_all = "camelCase")]
51pub struct UpdateServiceLevelAgreementDto {
52    #[cfg_attr(feature = "openapi", schema(example = "example"))]
53    pub name: String,
54    #[cfg_attr(feature = "openapi", schema(example = true))]
55    #[serde(alias = "is_default")]
56    pub is_default: bool,
57    pub status: ServiceLevelAgreementStatus,
58}
59
60// =============================================================================
61// Patch DTO
62// =============================================================================
63
64/// Request DTO for partial update of a ServiceLevelAgreement
65///
66/// Used in PATCH requests for partial updates.
67/// All fields are optional - only provided fields will be updated.
68#[derive(Debug, Clone, Default, Deserialize)]
69#[cfg_attr(feature = "openapi", derive(ToSchema))]
70#[serde(rename_all = "camelCase")]
71pub struct PatchServiceLevelAgreementDto {
72    #[cfg_attr(feature = "openapi", schema(example = "example"))]
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub name: Option<String>,
75    #[cfg_attr(feature = "openapi", schema(example = true))]
76    #[serde(skip_serializing_if = "Option::is_none", alias = "is_default")]
77    pub is_default: Option<bool>,
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub status: Option<ServiceLevelAgreementStatus>,
80}
81
82impl PatchServiceLevelAgreementDto {
83    /// Check if any field is set
84    pub fn has_changes(&self) -> bool {
85        self.name.is_some() || self.is_default.is_some() || self.status.is_some()
86    }
87}
88
89// =============================================================================
90// Response DTO
91// =============================================================================
92
93/// Response DTO for ServiceLevelAgreement entity
94///
95/// Used in API responses for single entity.
96/// Includes all fields including metadata.
97#[derive(Debug, Clone, Serialize)]
98#[cfg_attr(feature = "openapi", derive(ToSchema))]
99#[serde(rename_all = "camelCase")]
100pub struct ServiceLevelAgreementResponseDto {
101    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
102    pub id: Uuid,
103    #[cfg_attr(feature = "openapi", schema(example = "example"))]
104    pub name: String,
105    #[cfg_attr(feature = "openapi", schema(example = true))]
106    pub is_default: bool,
107    pub status: ServiceLevelAgreementStatus,
108    pub metadata: AuditMetadata,
109}
110
111// =============================================================================
112// List Response DTO
113// =============================================================================
114
115/// Paginated list response for ServiceLevelAgreement entities
116///
117/// Used in API responses for list endpoints.
118/// Includes pagination metadata.
119#[derive(Debug, Clone, Serialize)]
120#[cfg_attr(feature = "openapi", derive(ToSchema))]
121#[serde(rename_all = "camelCase")]
122pub struct ServiceLevelAgreementListResponseDto {
123    /// List of items
124    pub items: Vec<ServiceLevelAgreementResponseDto>,
125    /// Total number of items (across all pages)
126    pub total: u64,
127    /// Current page number (1-indexed)
128    pub page: u32,
129    /// Number of items per page
130    pub per_page: u32,
131    /// Total number of pages
132    pub total_pages: u32,
133    /// Whether there is a next page
134    pub has_next: bool,
135    /// Whether there is a previous page
136    pub has_prev: bool,
137}
138
139impl ServiceLevelAgreementListResponseDto {
140    /// Create a new list response from items and pagination info
141    pub fn new(items: Vec<ServiceLevelAgreementResponseDto>, total: u64, page: u32, per_page: u32) -> Self {
142        let total_pages = if per_page > 0 {
143            ((total as f64) / (per_page as f64)).ceil() as u32
144        } else {
145            0
146        };
147        Self {
148            items,
149            total,
150            page,
151            per_page,
152            total_pages,
153            has_next: page < total_pages,
154            has_prev: page > 1,
155        }
156    }
157}
158
159/// Summary DTO for list views (compact version)
160#[derive(Debug, Clone, Serialize)]
161#[cfg_attr(feature = "openapi", derive(ToSchema))]
162#[serde(rename_all = "camelCase")]
163pub struct ServiceLevelAgreementSummaryDto {
164    pub id: Uuid,
165    pub name: String,
166    pub is_default: bool,
167    pub status: ServiceLevelAgreementStatus,
168    pub created_at: Option<DateTime<Utc>>,
169}
170
171// =============================================================================
172// Conversions
173// =============================================================================
174
175impl From<ServiceLevelAgreement> for ServiceLevelAgreementResponseDto {
176    fn from(entity: ServiceLevelAgreement) -> Self {
177        Self {
178            id: entity.id,
179            name: entity.name,
180            is_default: entity.is_default,
181            status: entity.status,
182            metadata: entity.metadata,
183        }
184    }
185}
186
187impl From<ServiceLevelAgreement> for ServiceLevelAgreementSummaryDto {
188    fn from(entity: ServiceLevelAgreement) -> Self {
189        let created_at = backbone_core::PersistentEntity::created_at(&entity);
190        Self {
191            id: entity.id,
192            name: entity.name,
193            is_default: entity.is_default,
194            status: entity.status,
195            created_at,
196        }
197    }
198}
199
200impl From<CreateServiceLevelAgreementDto> for ServiceLevelAgreement {
201    fn from(dto: CreateServiceLevelAgreementDto) -> Self {
202        Self {
203            id: Uuid::new_v4(),
204            name: dto.name,
205            is_default: dto.is_default,
206            status: dto.status,
207            metadata: AuditMetadata::default(),
208        }
209    }
210}
211
212impl From<&ServiceLevelAgreement> for ServiceLevelAgreementResponseDto {
213    fn from(entity: &ServiceLevelAgreement) -> Self {
214        Self {
215            id: entity.id.clone(),
216            name: entity.name.clone(),
217            is_default: entity.is_default.clone(),
218            status: entity.status.clone(),
219            metadata: entity.metadata.clone(),
220        }
221    }
222}
223
224impl backbone_core::FromCreateDto<CreateServiceLevelAgreementDto> for ServiceLevelAgreement {
225    fn from_create_dto(dto: CreateServiceLevelAgreementDto) -> backbone_core::ServiceResult<Self> {
226        Ok(ServiceLevelAgreement::from(dto))
227    }
228}
229
230impl backbone_core::ApplyUpdateDto<UpdateServiceLevelAgreementDto> for ServiceLevelAgreement {
231    fn apply_update(mut self, dto: UpdateServiceLevelAgreementDto) -> backbone_core::ServiceResult<Self> {
232        self.name = dto.name;
233        self.is_default = dto.is_default;
234        self.status = dto.status;
235        Ok(self)
236    }
237}
238
239// =============================================================================
240// Custom DTOs
241// =============================================================================
242
243// Add custom DTOs specific to ServiceLevelAgreement here.
244// This section will be preserved during regeneration.
245// >>> END CUSTOM DTOs
246