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