Skip to main content

backbone_support/presentation/dto/
service_level_priority_dto.rs

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