backbone-bucket 0.4.0

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
//! StoredFile DTOs (Data Transfer Objects)
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! DTOs provide a clean separation between domain entities and API
//! representations, with validation and OpenAPI documentation support.

use serde::{Deserialize, Serialize};
use uuid::Uuid;
use chrono::{DateTime, Utc};

#[cfg(feature = "openapi")]
#[cfg(feature = "openapi")]
use utoipa::ToSchema;

#[cfg(feature = "validation")]
use validator::Validate;

use crate::domain::entity::StoredFile;
use crate::domain::entity::AuditMetadata;
use crate::domain::entity::FileStatus;
use crate::domain::entity::ProcessingStatus;
use crate::domain::entity::ThreatLevel;

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

/// Request DTO for creating a new StoredFile
///
/// 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))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct CreateStoredFileDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "bucket_id")]
    pub bucket_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "owner_id")]
    pub owner_id: Uuid,
    #[cfg_attr(feature = "validation", validate(length(max = 1024)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub path: String,
    #[cfg_attr(feature = "validation", validate(length(max = 255)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "original_name")]
    pub original_name: String,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(alias = "size_bytes")]
    pub size_bytes: i64,
    #[cfg_attr(feature = "validation", validate(length(max = 127)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "mime_type")]
    pub mime_type: String,
    #[cfg_attr(feature = "validation", validate(length(max = 128)))]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub checksum: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "is_compressed")]
    pub is_compressed: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "original_size")]
    pub original_size: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "compression_algorithm")]
    pub compression_algorithm: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "is_scanned")]
    pub is_scanned: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "scan_result")]
    pub scan_result: Option<serde_json::Value>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "threat_level")]
    pub threat_level: Option<ThreatLevel>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "has_thumbnail")]
    pub has_thumbnail: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "thumbnail_path")]
    pub thumbnail_path: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "has_video_thumbnail")]
    pub has_video_thumbnail: bool,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "has_document_preview")]
    pub has_document_preview: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "processing_status")]
    pub processing_status: Option<ProcessingStatus>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "content_hash_id")]
    pub content_hash_id: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "cdn_url")]
    pub cdn_url: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "cdn_url_expires_at")]
    pub cdn_url_expires_at: Option<DateTime<Utc>>,
    #[cfg_attr(feature = "validation", validate(length(max = 100)))]
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "owner_module")]
    pub owner_module: Option<String>,
    #[cfg_attr(feature = "validation", validate(length(max = 100)))]
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "owner_entity")]
    pub owner_entity: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "owner_entity_id")]
    pub owner_entity_id: Option<Uuid>,
    #[cfg_attr(feature = "validation", validate(length(max = 100)))]
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "field_name")]
    pub field_name: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(alias = "sort_order")]
    pub sort_order: i32,
    pub status: FileStatus,
    #[cfg_attr(feature = "validation", validate(length(max = 1024)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "storage_key")]
    pub storage_key: String,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub version: i32,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "previous_version_id")]
    pub previous_version_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(alias = "download_count")]
    pub download_count: i32,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "last_accessed_at")]
    pub last_accessed_at: Option<DateTime<Utc>>,
}

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

/// Request DTO for full update of a StoredFile
///
/// 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))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct UpdateStoredFileDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "bucket_id")]
    pub bucket_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(alias = "owner_id")]
    pub owner_id: Uuid,
    #[cfg_attr(feature = "validation", validate(length(max = 1024)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub path: String,
    #[cfg_attr(feature = "validation", validate(length(max = 255)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "original_name")]
    pub original_name: String,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(alias = "size_bytes")]
    pub size_bytes: i64,
    #[cfg_attr(feature = "validation", validate(length(max = 127)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "mime_type")]
    pub mime_type: String,
    #[cfg_attr(feature = "validation", validate(length(max = 128)))]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub checksum: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "is_compressed")]
    pub is_compressed: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "original_size")]
    pub original_size: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "compression_algorithm")]
    pub compression_algorithm: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "is_scanned")]
    pub is_scanned: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "scan_result")]
    pub scan_result: Option<serde_json::Value>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "threat_level")]
    pub threat_level: Option<ThreatLevel>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "has_thumbnail")]
    pub has_thumbnail: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "thumbnail_path")]
    pub thumbnail_path: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "has_video_thumbnail")]
    pub has_video_thumbnail: bool,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(alias = "has_document_preview")]
    pub has_document_preview: bool,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "processing_status")]
    pub processing_status: Option<ProcessingStatus>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "content_hash_id")]
    pub content_hash_id: Option<Uuid>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "cdn_url")]
    pub cdn_url: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "cdn_url_expires_at")]
    pub cdn_url_expires_at: Option<DateTime<Utc>>,
    #[cfg_attr(feature = "validation", validate(length(max = 100)))]
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "owner_module")]
    pub owner_module: Option<String>,
    #[cfg_attr(feature = "validation", validate(length(max = 100)))]
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "owner_entity")]
    pub owner_entity: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "owner_entity_id")]
    pub owner_entity_id: Option<Uuid>,
    #[cfg_attr(feature = "validation", validate(length(max = 100)))]
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "field_name")]
    pub field_name: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(alias = "sort_order")]
    pub sort_order: i32,
    pub status: FileStatus,
    #[cfg_attr(feature = "validation", validate(length(max = 1024)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(alias = "storage_key")]
    pub storage_key: String,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub version: i32,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "previous_version_id")]
    pub previous_version_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(alias = "download_count")]
    pub download_count: i32,
    #[serde(default, skip_serializing_if = "Option::is_none", alias = "last_accessed_at")]
    pub last_accessed_at: Option<DateTime<Utc>>,
}

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

/// Request DTO for partial update of a StoredFile
///
/// 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))]
#[cfg_attr(feature = "validation", derive(Validate))]
#[serde(rename_all = "camelCase")]
pub struct PatchStoredFileDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "bucket_id")]
    pub bucket_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "owner_id")]
    pub owner_id: Option<Uuid>,
    #[cfg_attr(feature = "validation", validate(length(max = 1024)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<String>,
    #[cfg_attr(feature = "validation", validate(length(max = 255)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "original_name")]
    pub original_name: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "size_bytes")]
    pub size_bytes: Option<i64>,
    #[cfg_attr(feature = "validation", validate(length(max = 127)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "mime_type")]
    pub mime_type: Option<String>,
    #[cfg_attr(feature = "validation", validate(length(max = 128)))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub checksum: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "is_compressed")]
    pub is_compressed: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "original_size")]
    pub original_size: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "compression_algorithm")]
    pub compression_algorithm: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "is_scanned")]
    pub is_scanned: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "scan_result")]
    pub scan_result: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "threat_level")]
    pub threat_level: Option<ThreatLevel>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "has_thumbnail")]
    pub has_thumbnail: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "thumbnail_path")]
    pub thumbnail_path: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "has_video_thumbnail")]
    pub has_video_thumbnail: Option<bool>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "has_document_preview")]
    pub has_document_preview: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "processing_status")]
    pub processing_status: Option<ProcessingStatus>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "content_hash_id")]
    pub content_hash_id: Option<Uuid>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "cdn_url")]
    pub cdn_url: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "cdn_url_expires_at")]
    pub cdn_url_expires_at: Option<DateTime<Utc>>,
    #[cfg_attr(feature = "validation", validate(length(max = 100)))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "owner_module")]
    pub owner_module: Option<String>,
    #[cfg_attr(feature = "validation", validate(length(max = 100)))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "owner_entity")]
    pub owner_entity: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "owner_entity_id")]
    pub owner_entity_id: Option<Uuid>,
    #[cfg_attr(feature = "validation", validate(length(max = 100)))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "field_name")]
    pub field_name: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "sort_order")]
    pub sort_order: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<FileStatus>,
    #[cfg_attr(feature = "validation", validate(length(max = 1024)))]
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "storage_key")]
    pub storage_key: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "previous_version_id")]
    pub previous_version_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    #[serde(skip_serializing_if = "Option::is_none", alias = "download_count")]
    pub download_count: Option<i32>,
    #[serde(skip_serializing_if = "Option::is_none", alias = "last_accessed_at")]
    pub last_accessed_at: Option<DateTime<Utc>>,
}

impl PatchStoredFileDto {
    /// Check if any field is set
    pub fn has_changes(&self) -> bool {
        self.bucket_id.is_some() || self.owner_id.is_some() || self.path.is_some() || self.original_name.is_some() || self.size_bytes.is_some() || self.mime_type.is_some() || self.checksum.is_some() || self.is_compressed.is_some() || self.original_size.is_some() || self.compression_algorithm.is_some() || self.is_scanned.is_some() || self.scan_result.is_some() || self.threat_level.is_some() || self.has_thumbnail.is_some() || self.thumbnail_path.is_some() || self.has_video_thumbnail.is_some() || self.has_document_preview.is_some() || self.processing_status.is_some() || self.content_hash_id.is_some() || self.cdn_url.is_some() || self.cdn_url_expires_at.is_some() || self.owner_module.is_some() || self.owner_entity.is_some() || self.owner_entity_id.is_some() || self.field_name.is_some() || self.sort_order.is_some() || self.status.is_some() || self.storage_key.is_some() || self.version.is_some() || self.previous_version_id.is_some() || self.download_count.is_some() || self.last_accessed_at.is_some()
    }
}

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

/// Response DTO for StoredFile 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 StoredFileResponseDto {
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub bucket_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "550e8400-e29b-41d4-a716-446655440000"))]
    pub owner_id: Uuid,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub path: String,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub original_name: String,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub size_bytes: i64,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub mime_type: String,
    pub checksum: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub is_compressed: bool,
    pub original_size: Option<i64>,
    pub compression_algorithm: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub is_scanned: bool,
    pub scan_result: Option<serde_json::Value>,
    pub threat_level: Option<ThreatLevel>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub has_thumbnail: bool,
    pub thumbnail_path: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub has_video_thumbnail: bool,
    #[cfg_attr(feature = "openapi", schema(example = true))]
    pub has_document_preview: bool,
    pub processing_status: Option<ProcessingStatus>,
    pub content_hash_id: Option<Uuid>,
    pub cdn_url: Option<String>,
    pub cdn_url_expires_at: Option<DateTime<Utc>>,
    pub owner_module: Option<String>,
    pub owner_entity: Option<String>,
    pub owner_entity_id: Option<Uuid>,
    pub field_name: Option<String>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub sort_order: i32,
    pub status: FileStatus,
    #[cfg_attr(feature = "openapi", schema(example = "example"))]
    pub storage_key: String,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub version: i32,
    pub previous_version_id: Option<Uuid>,
    #[cfg_attr(feature = "openapi", schema(example = 42))]
    pub download_count: i32,
    pub last_accessed_at: Option<DateTime<Utc>>,
    pub metadata: AuditMetadata,
}

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

/// Paginated list response for StoredFile 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 StoredFileListResponseDto {
    /// List of items
    pub items: Vec<StoredFileResponseDto>,
    /// 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 StoredFileListResponseDto {
    /// Create a new list response from items and pagination info
    pub fn new(items: Vec<StoredFileResponseDto>, 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 StoredFileSummaryDto {
    pub id: Uuid,
    pub bucket_id: Uuid,
    pub owner_id: Uuid,
    pub path: String,
    pub created_at: Option<DateTime<Utc>>,
}

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

impl From<StoredFile> for StoredFileResponseDto {
    fn from(entity: StoredFile) -> Self {
        Self {
            id: entity.id,
            bucket_id: entity.bucket_id,
            owner_id: entity.owner_id,
            path: entity.path,
            original_name: entity.original_name,
            size_bytes: entity.size_bytes,
            mime_type: entity.mime_type,
            checksum: entity.checksum,
            is_compressed: entity.is_compressed,
            original_size: entity.original_size,
            compression_algorithm: entity.compression_algorithm,
            is_scanned: entity.is_scanned,
            scan_result: entity.scan_result,
            threat_level: entity.threat_level,
            has_thumbnail: entity.has_thumbnail,
            thumbnail_path: entity.thumbnail_path,
            has_video_thumbnail: entity.has_video_thumbnail,
            has_document_preview: entity.has_document_preview,
            processing_status: entity.processing_status,
            content_hash_id: entity.content_hash_id,
            cdn_url: entity.cdn_url,
            cdn_url_expires_at: entity.cdn_url_expires_at,
            owner_module: entity.owner_module,
            owner_entity: entity.owner_entity,
            owner_entity_id: entity.owner_entity_id,
            field_name: entity.field_name,
            sort_order: entity.sort_order,
            status: entity.status,
            storage_key: entity.storage_key,
            version: entity.version,
            previous_version_id: entity.previous_version_id,
            download_count: entity.download_count,
            last_accessed_at: entity.last_accessed_at,
            metadata: entity.metadata,
        }
    }
}

impl From<StoredFile> for StoredFileSummaryDto {
    fn from(entity: StoredFile) -> Self {
        let created_at = backbone_core::PersistentEntity::created_at(&entity);
        Self {
            id: entity.id,
            bucket_id: entity.bucket_id,
            owner_id: entity.owner_id,
            path: entity.path,
            created_at,
        }
    }
}

impl From<CreateStoredFileDto> for StoredFile {
    fn from(dto: CreateStoredFileDto) -> Self {
        Self {
            id: Uuid::new_v4(),
            bucket_id: dto.bucket_id,
            owner_id: dto.owner_id,
            path: dto.path,
            original_name: dto.original_name,
            size_bytes: dto.size_bytes,
            mime_type: dto.mime_type,
            checksum: dto.checksum,
            is_compressed: dto.is_compressed,
            original_size: dto.original_size,
            compression_algorithm: dto.compression_algorithm,
            is_scanned: dto.is_scanned,
            scan_result: dto.scan_result,
            threat_level: dto.threat_level,
            has_thumbnail: dto.has_thumbnail,
            thumbnail_path: dto.thumbnail_path,
            has_video_thumbnail: dto.has_video_thumbnail,
            has_document_preview: dto.has_document_preview,
            processing_status: dto.processing_status,
            content_hash_id: dto.content_hash_id,
            cdn_url: dto.cdn_url,
            cdn_url_expires_at: dto.cdn_url_expires_at,
            owner_module: dto.owner_module,
            owner_entity: dto.owner_entity,
            owner_entity_id: dto.owner_entity_id,
            field_name: dto.field_name,
            sort_order: dto.sort_order,
            status: dto.status,
            storage_key: dto.storage_key,
            version: dto.version,
            previous_version_id: dto.previous_version_id,
            download_count: dto.download_count,
            last_accessed_at: dto.last_accessed_at,
            metadata: AuditMetadata::default(),
        }
    }
}

impl From<&StoredFile> for StoredFileResponseDto {
    fn from(entity: &StoredFile) -> Self {
        Self {
            id: entity.id.clone(),
            bucket_id: entity.bucket_id.clone(),
            owner_id: entity.owner_id.clone(),
            path: entity.path.clone(),
            original_name: entity.original_name.clone(),
            size_bytes: entity.size_bytes.clone(),
            mime_type: entity.mime_type.clone(),
            checksum: entity.checksum.clone(),
            is_compressed: entity.is_compressed.clone(),
            original_size: entity.original_size.clone(),
            compression_algorithm: entity.compression_algorithm.clone(),
            is_scanned: entity.is_scanned.clone(),
            scan_result: entity.scan_result.clone(),
            threat_level: entity.threat_level.clone(),
            has_thumbnail: entity.has_thumbnail.clone(),
            thumbnail_path: entity.thumbnail_path.clone(),
            has_video_thumbnail: entity.has_video_thumbnail.clone(),
            has_document_preview: entity.has_document_preview.clone(),
            processing_status: entity.processing_status.clone(),
            content_hash_id: entity.content_hash_id.clone(),
            cdn_url: entity.cdn_url.clone(),
            cdn_url_expires_at: entity.cdn_url_expires_at.clone(),
            owner_module: entity.owner_module.clone(),
            owner_entity: entity.owner_entity.clone(),
            owner_entity_id: entity.owner_entity_id.clone(),
            field_name: entity.field_name.clone(),
            sort_order: entity.sort_order.clone(),
            status: entity.status.clone(),
            storage_key: entity.storage_key.clone(),
            version: entity.version.clone(),
            previous_version_id: entity.previous_version_id.clone(),
            download_count: entity.download_count.clone(),
            last_accessed_at: entity.last_accessed_at.clone(),
            metadata: entity.metadata.clone(),
        }
    }
}

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

impl backbone_core::ApplyUpdateDto<UpdateStoredFileDto> for StoredFile {
    fn apply_update(mut self, dto: UpdateStoredFileDto) -> backbone_core::ServiceResult<Self> {
        self.bucket_id = dto.bucket_id;
        self.owner_id = dto.owner_id;
        self.path = dto.path;
        self.original_name = dto.original_name;
        self.size_bytes = dto.size_bytes;
        self.mime_type = dto.mime_type;
        self.checksum = dto.checksum;
        self.is_compressed = dto.is_compressed;
        self.original_size = dto.original_size;
        self.compression_algorithm = dto.compression_algorithm;
        self.is_scanned = dto.is_scanned;
        self.scan_result = dto.scan_result;
        self.threat_level = dto.threat_level;
        self.has_thumbnail = dto.has_thumbnail;
        self.thumbnail_path = dto.thumbnail_path;
        self.has_video_thumbnail = dto.has_video_thumbnail;
        self.has_document_preview = dto.has_document_preview;
        self.processing_status = dto.processing_status;
        self.content_hash_id = dto.content_hash_id;
        self.cdn_url = dto.cdn_url;
        self.cdn_url_expires_at = dto.cdn_url_expires_at;
        self.owner_module = dto.owner_module;
        self.owner_entity = dto.owner_entity;
        self.owner_entity_id = dto.owner_entity_id;
        self.field_name = dto.field_name;
        self.sort_order = dto.sort_order;
        self.status = dto.status;
        self.storage_key = dto.storage_key;
        self.version = dto.version;
        self.previous_version_id = dto.previous_version_id;
        self.download_count = dto.download_count;
        self.last_accessed_at = dto.last_accessed_at;
        Ok(self)
    }
}

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

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