fortress-api-server 1.0.0

REST API server for Fortress secure database system
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
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
//! API models and data structures
//!
//! This module defines the request and response models used by the REST API,
//! including data transfer objects (DTOs) and validation structures.

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use chrono::{DateTime, Utc};

/// API response wrapper
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct ApiResponse<T> {
    /// Response data
    pub data: Option<T>,
    /// Success status
    pub success: bool,
    /// Response timestamp
    pub timestamp: DateTime<Utc>,
    /// Response metadata
    pub metadata: Option<ResponseMetadata>,
}

impl<T> ApiResponse<T> {
    /// Create a successful response
    pub fn success(data: T) -> Self {
        Self {
            data: Some(data),
            success: true,
            timestamp: Utc::now(),
            metadata: None,
        }
    }

    /// Create a successful response with metadata
    pub fn success_with_metadata(data: T, metadata: ResponseMetadata) -> Self {
        Self {
            data: Some(data),
            success: true,
            timestamp: Utc::now(),
            metadata: Some(metadata),
        }
    }

    /// Create an empty successful response
    pub fn empty() -> Self {
        Self {
            data: None,
            success: true,
            timestamp: Utc::now(),
            metadata: None,
        }
    }
}

/// Response metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResponseMetadata {
    /// Total count (for paginated responses)
    pub total_count: Option<u64>,
    /// Page information
    pub page: Option<PageInfo>,
    /// Rate limit information
    pub rate_limit: Option<RateLimitInfo>,
    /// Request ID
    pub request_id: Option<String>,
}

/// Page information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PageInfo {
    /// Current page number
    pub page: u32,
    /// Page size
    pub page_size: u32,
    /// Total pages
    pub total_pages: u32,
    /// Has next page
    pub has_next: bool,
    /// Has previous page
    pub has_previous: bool,
}

/// Rate limit information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RateLimitInfo {
    /// Requests remaining
    pub remaining: u32,
    /// Requests limit
    pub limit: u32,
    /// Reset time
    pub reset_at: DateTime<Utc>,
}

/// Data storage request
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct StoreRequest {
    /// Data to store (will be automatically encrypted)
    pub data: serde_json::Value,
    /// Optional metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
    /// Encryption algorithm (optional, uses default if not specified)
    pub algorithm: Option<String>,
    /// Key ID (optional, generates new key if not specified)
    pub key_id: Option<String>,
    /// Tenant ID (for multi-tenant setups)
    pub tenant_id: Option<String>,
    /// Field-level encryption configuration
    pub field_encryption: Option<FieldEncryptionConfig>,
}

/// Field-level encryption configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FieldEncryptionConfig {
    /// Fields to encrypt with specific algorithms
    pub fields: HashMap<String, FieldConfig>,
}

/// Field configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FieldConfig {
    /// Encryption algorithm for this field
    pub algorithm: String,
    /// Key ID for this field (optional)
    pub key_id: Option<String>,
    /// Field sensitivity level
    pub sensitivity: Option<String>,
}

/// Data storage response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StoreResponse {
    /// ID of the stored data
    pub id: String,
    /// Key ID used for encryption
    pub key_id: String,
    /// Storage timestamp
    pub stored_at: DateTime<Utc>,
    /// Data size in bytes
    pub size_bytes: u64,
    /// Encryption algorithm used
    pub algorithm: String,
    /// Field encryption metadata
    pub field_metadata: Option<HashMap<String, FieldEncryptionMetadata>>,
}

/// Field encryption metadata
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FieldEncryptionMetadata {
    /// Field configuration ID
    pub config_id: String,
    /// Field identifier
    pub field: String,
    /// Algorithm used for encryption
    pub algorithm: String,
    /// Key ID used
    pub key_id: String,
    /// Key version
    pub key_version: u32,
    /// When the field was encrypted
    pub encrypted_at: DateTime<Utc>,
    /// Nonce/IV used (if applicable)
    pub nonce: Option<Vec<u8>>,
    /// Authentication tag (if applicable)
    pub tag: Option<Vec<u8>>,
    /// Additional encryption metadata
    pub metadata: HashMap<String, String>,
}

/// Re-export from fortress_core to avoid conflicts
pub use fortress_core::field_encryption::FieldEncryptionMetadata as CoreFieldEncryptionMetadata;

/// Conversion from core metadata to API metadata
impl From<CoreFieldEncryptionMetadata> for FieldEncryptionMetadata {
    fn from(core: CoreFieldEncryptionMetadata) -> Self {
        Self {
            config_id: core.config_id.to_string(),
            field: match core.field {
                fortress_core::field_encryption::FieldIdentifier::Name(name) => name,
                fortress_core::field_encryption::FieldIdentifier::Path(path) => path.join("."),
                fortress_core::field_encryption::FieldIdentifier::Indexed { index, .. } => format!("[{}]", index),
            },
            algorithm: core.algorithm,
            key_id: core.key_id.to_string(),
            key_version: core.key_version,
            encrypted_at: core.encrypted_at,
            nonce: core.nonce,
            tag: core.tag,
            metadata: core.metadata,
        }
    }
}

/// Data retrieval request
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct RetrieveRequest {
    /// ID of the data to retrieve
    pub id: String,
    /// Key ID for decryption (optional, uses stored key if not specified)
    pub key_id: Option<String>,
    /// Tenant ID (for multi-tenant setups)
    pub tenant_id: Option<String>,
    /// Include raw encrypted data
    pub include_encrypted: Option<bool>,
}

/// Data retrieval response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RetrieveResponse {
    /// Decrypted data
    pub data: serde_json::Value,
    /// Original metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
    /// Retrieval timestamp
    pub retrieved_at: DateTime<Utc>,
    /// Storage timestamp
    pub stored_at: DateTime<Utc>,
    /// Encryption algorithm used
    pub algorithm: String,
    /// Key ID used
    pub key_id: String,
    /// Raw encrypted data (if requested)
    pub encrypted_data: Option<String>,
    /// Field decryption metadata
    pub field_metadata: Option<HashMap<String, FieldEncryptionMetadata>>,
}

/// Data deletion request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteRequest {
    /// ID of the data to delete
    pub id: String,
    /// Tenant ID (for multi-tenant setups)
    pub tenant_id: Option<String>,
    /// Soft delete (mark as deleted but keep data)
    pub soft_delete: Option<bool>,
}

/// Data deletion response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteResponse {
    /// ID of the deleted data
    pub id: String,
    /// Deletion timestamp
    pub deleted_at: DateTime<Utc>,
    /// Whether it was a soft delete
    pub soft_delete: bool,
}

/// List data request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListRequest {
    /// Tenant ID (for multi-tenant setups)
    pub tenant_id: Option<String>,
    /// Pagination parameters
    pub pagination: Option<PaginationParams>,
    /// Filter parameters
    pub filter: Option<FilterParams>,
    /// Sort parameters
    pub sort: Option<SortParams>,
}

/// Pagination parameters
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaginationParams {
    /// Page number (1-based)
    pub page: Option<u32>,
    /// Page size
    pub page_size: Option<u32>,
    /// Maximum items to return
    pub limit: Option<u32>,
}

/// Filter parameters
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterParams {
    /// Filter by metadata key-value pairs
    pub metadata: Option<HashMap<String, serde_json::Value>>,
    /// Filter by algorithm
    pub algorithm: Option<String>,
    /// Filter by date range
    pub date_range: Option<DateRange>,
    /// Filter by key ID
    pub key_id: Option<String>,
}

/// Date range filter
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DateRange {
    /// Start date (inclusive)
    pub start: Option<DateTime<Utc>>,
    /// End date (inclusive)
    pub end: Option<DateTime<Utc>>,
}

/// Sort parameters
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SortParams {
    /// Sort field
    pub field: String,
    /// Sort direction
    pub direction: SortDirection,
}

/// Sort direction
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum SortDirection {
    /// Ascending order
    Asc,
    /// Descending order
    Desc,
}

/// List data response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListResponse {
    /// List of data items
    pub items: Vec<DataItem>,
    /// Total count
    pub total_count: u64,
}

/// Data item summary
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DataItem {
    /// Data ID
    pub id: String,
    /// Key ID
    pub key_id: String,
    /// Storage timestamp
    pub stored_at: DateTime<Utc>,
    /// Data size in bytes
    pub size_bytes: u64,
    /// Algorithm used
    pub algorithm: String,
    /// Metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
}

/// Key management request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyRequest {
    /// Key type/algorithm
    pub algorithm: String,
    /// Key size in bits (optional, uses algorithm default)
    pub key_size: Option<u32>,
    /// Metadata
    pub metadata: Option<HashMap<String, serde_json::Value>>,
    /// Tenant ID (for multi-tenant setups)
    pub tenant_id: Option<String>,
}

/// Key management response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KeyResponse {
    /// Key ID
    pub id: String,
    /// Key type/algorithm
    pub algorithm: String,
    /// Key size in bits
    pub key_size: u32,
    /// Creation timestamp
    pub created_at: DateTime<Utc>,
    /// Key metadata
    pub metadata: HashMap<String, serde_json::Value>,
    /// Key fingerprint (for verification)
    pub fingerprint: String,
}

/// Health check response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthResponse {
    /// Overall health status
    pub status: HealthStatus,
    /// Service version
    pub version: String,
    /// Uptime in seconds
    pub uptime: u64,
    /// Individual component health
    pub components: HashMap<String, ComponentHealth>,
    /// Timestamp
    pub timestamp: DateTime<Utc>,
}

/// Health status
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum HealthStatus {
    /// Healthy
    Healthy,
    /// Degraded performance
    Degraded,
    /// Unhealthy
    Unhealthy,
}

/// Component health information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComponentHealth {
    /// Component status
    pub status: HealthStatus,
    /// Status message
    pub message: Option<String>,
    /// Response time in milliseconds
    pub response_time_ms: Option<u64>,
    /// Last check timestamp
    pub last_check: DateTime<Utc>,
}

/// Metrics response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetricsResponse {
    /// Metrics data
    pub metrics: HashMap<String, serde_json::Value>,
    /// Collection timestamp
    pub timestamp: DateTime<Utc>,
}

/// Authentication request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthRequest {
    /// Username or email
    pub username: String,
    /// Password
    pub password: String,
    /// Tenant ID (for multi-tenant setups)
    pub tenant_id: Option<String>,
}

/// Authentication response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthResponse {
    /// Access token
    pub access_token: String,
    /// Token type
    pub token_type: String,
    /// Token expiration in seconds
    pub expires_in: u64,
    /// Refresh token (optional)
    pub refresh_token: Option<String>,
    /// User information
    pub user: UserInfo,
}

/// User information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UserInfo {
    /// User ID
    pub id: String,
    /// Username
    pub username: String,
    /// Email
    pub email: Option<String>,
    /// Roles
    pub roles: Vec<String>,
    /// Tenant ID
    pub tenant_id: Option<String>,
}

/// Token refresh request
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct RefreshTokenRequest {
    /// Refresh token
    pub refresh_token: String,
}

/// Token refresh response
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct RefreshTokenResponse {
    /// New access token
    pub access_token: String,
    /// Token type
    pub token_type: String,
    /// Token expiration in seconds
    pub expires_in: u64,
    /// New refresh token (optional)
    pub refresh_token: Option<String>,
}

// ==================== DATABASE MANAGEMENT MODELS ====================

/// Create database request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateDatabaseRequest {
    /// Database name
    pub name: String,
    /// Encryption algorithm
    pub algorithm: String,
    /// Key rotation interval
    pub key_rotation_interval: String,
    /// Storage path
    pub storage_path: String,
}

/// Database response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseResponse {
    /// Database name
    pub name: String,
    /// Creation timestamp
    pub created_at: DateTime<Utc>,
    /// Encryption algorithm
    pub algorithm: String,
    /// Key rotation interval
    pub key_rotation_interval: String,
    /// Number of tables
    pub tables_count: u32,
    /// Database size in bytes
    pub size_bytes: u64,
}

/// List databases response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListDatabasesResponse {
    /// List of databases
    pub databases: Vec<DatabaseInfo>,
    /// Total count
    pub total_count: u64,
}

/// Database information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseInfo {
    /// Database name
    pub name: String,
    /// Creation timestamp
    pub created_at: DateTime<Utc>,
    /// Number of tables
    pub tables_count: u32,
    /// Database size in bytes
    pub size_bytes: u64,
}

/// Operation delete response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OperationDeleteResponse {
    /// Whether the operation was successful
    pub deleted: bool,
    /// Operation message
    pub message: String,
}

// ==================== TABLE MANAGEMENT MODELS ====================

/// Create table request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateTableRequest {
    /// Table name
    pub name: String,
    /// Table columns
    pub columns: Vec<ColumnDefinition>,
    /// Table encryption profile
    pub encryption: Option<String>,
    /// Column-specific encryption
    pub column_encryption: Option<HashMap<String, String>>,
}

/// Column definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ColumnDefinition {
    /// Column name
    pub name: String,
    /// Column type
    #[serde(rename = "type")]
    pub column_type: String,
    /// Whether it's a primary key
    pub primary_key: Option<bool>,
    /// Whether it's nullable
    pub nullable: Option<bool>,
    /// Encryption configuration
    pub encryption: Option<String>,
}

/// Table response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TableResponse {
    /// Table name
    pub name: String,
    /// Number of columns
    pub columns: u32,
    /// Number of rows
    pub rows: u64,
    /// Encryption profile
    pub encryption: String,
    /// Creation timestamp
    pub created_at: DateTime<Utc>,
}

/// List tables response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListTablesResponse {
    /// List of tables
    pub tables: Vec<TableInfo>,
    /// Total count
    pub total_count: u64,
}

/// Table information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TableInfo {
    /// Table name
    pub name: String,
    /// Number of columns
    pub columns: u32,
    /// Number of rows
    pub rows: u64,
    /// Encryption profile
    pub encryption: String,
    /// Creation timestamp
    pub created_at: DateTime<Utc>,
}

/// Table schema response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TableSchemaResponse {
    /// Table name
    pub name: String,
    /// Table columns
    pub columns: Vec<ColumnSchema>,
    /// Encryption profile
    pub encryption: String,
}

/// Column schema
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ColumnSchema {
    /// Column name
    pub name: String,
    /// Column type
    #[serde(rename = "type")]
    pub column_type: String,
    /// Whether it's a primary key
    pub primary_key: bool,
    /// Whether it's nullable
    pub nullable: bool,
    /// Whether it's encrypted
    pub encrypted: bool,
    /// Encryption algorithm (if encrypted)
    pub encryption_algorithm: Option<String>,
}

// ==================== DATA OPERATIONS MODELS ====================

/// Insert data request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InsertDataRequest {
    /// Data to insert (JSON object)
    #[serde(flatten)]
    pub data: serde_json::Value,
}

/// Insert response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InsertResponse {
    /// Inserted record ID
    pub id: String,
    /// Insert timestamp
    pub inserted_at: DateTime<Utc>,
    /// Number of rows affected
    pub rows_affected: u64,
}

/// Query response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QueryResponse {
    /// Query results
    pub results: Vec<serde_json::Value>,
    /// Total count
    pub total_count: u64,
    /// Execution time in milliseconds
    pub execution_time_ms: f64,
}

/// Bulk insert request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BulkInsertRequest {
    /// Data to insert (array of objects)
    pub data: Vec<serde_json::Value>,
}

/// Bulk insert response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BulkInsertResponse {
    /// Number of records inserted
    pub inserted_count: u64,
    /// Insert timestamp
    pub inserted_at: DateTime<Utc>,
    /// Execution time in milliseconds
    pub execution_time_ms: f64,
}

/// Update data request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateDataRequest {
    /// Data to update (JSON object with fields to update)
    #[serde(flatten)]
    pub data: serde_json::Value,
}

/// Update response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateResponse {
    /// Updated record ID
    pub id: String,
    /// Update timestamp
    pub updated_at: DateTime<Utc>,
    /// Number of rows affected
    pub rows_affected: u64,
}

// ==================== QUERY OPERATIONS MODELS ====================

/// Execute query request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExecuteQueryRequest {
    /// SQL query
    pub sql: String,
    /// Query parameters
    pub parameters: Option<Vec<serde_json::Value>>,
    /// Query options
    pub options: Option<HashMap<String, String>>,
}

// ==================== ENCRYPTION MANAGEMENT MODELS ====================

/// Rotate keys response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RotateKeysResponse {
    /// Rotation operation ID
    pub rotation_id: String,
    /// Rotation status
    pub status: String,
    /// Start timestamp
    pub started_at: DateTime<Utc>,
    /// Completion timestamp
    pub completed_at: DateTime<Utc>,
    /// Number of rows rotated
    pub rows_rotated: u64,
}

/// Rotation status response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RotationStatusResponse {
    /// Rotation status
    pub rotation_status: String,
    /// Current key version
    pub current_version: u32,
    /// Previous key version
    pub previous_version: u32,
    /// Transition status
    pub transition_status: String,
    /// Start timestamp
    pub started_at: DateTime<Utc>,
    /// Estimated completion time
    pub estimated_completion: DateTime<Utc>,
}

/// Encryption metadata response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EncryptionMetadataResponse {
    /// Table encryption profile
    pub table_encryption: String,
    /// Column-specific encryption
    pub column_encryption: HashMap<String, String>,
    /// Key rotation schedule
    pub key_rotation_schedule: HashMap<String, String>,
    /// Last rotation timestamp
    pub last_rotation: DateTime<Utc>,
    /// Next rotation timestamp
    pub next_rotation: DateTime<Utc>,
    /// Zero-downtime rotation enabled
    pub zero_downtime_enabled: bool,
    /// Dual key validation enabled
    pub dual_key_validation: bool,
}

impl Default for PaginationParams {
    fn default() -> Self {
        Self {
            page: Some(1),
            page_size: Some(50),
            limit: None,
        }
    }
}

impl Default for SortParams {
    fn default() -> Self {
        Self {
            field: "stored_at".to_string(),
            direction: SortDirection::Desc,
        }
    }
}

// ==================== OPENAPI RESPONSE MODELS ====================

/// Store data response
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct StoreDataResponse {
    /// Unique identifier for stored data
    
    pub id: String,
    /// Key ID used for encryption
    
    pub key_id: String,
    /// Timestamp when data was stored
    
    pub stored_at: DateTime<Utc>,
    /// Size of stored data in bytes
    
    pub size_bytes: u64,
    /// Encryption algorithm used
    
    pub algorithm: String,
    /// Field-level encryption metadata
    
    pub field_metadata: Option<HashMap<String, serde_json::Value>>,
}

/// Retrieve data response
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct RetrieveDataResponse {
    /// Unique identifier for the data
    
    pub id: String,
    /// Decrypted data
    
    pub data: serde_json::Value,
    /// Metadata associated with the data
    
    pub metadata: Option<HashMap<String, serde_json::Value>>,
    /// Timestamp when data was created
    
    pub created_at: DateTime<Utc>,
    /// Last access timestamp
    
    pub last_accessed: Option<DateTime<Utc>>,
    /// Encryption algorithm used
    
    pub algorithm: String,
    /// Key ID used for encryption
    
    pub key_id: String,
    /// Field-level encryption metadata
    
    pub field_metadata: Option<HashMap<String, serde_json::Value>>,
}

/// List data response
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct ListDataResponse {
    /// List of storage records
    
    pub records: Vec<serde_json::Value>,
    /// Total count of records
    
    pub total_count: u64,
    /// Current page number
    
    pub page: u32,
    /// Page size
    
    pub page_size: u32,
    /// Total pages
    
    pub total_pages: u32,
}

/// Component status for health check
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct ComponentStatus {
    /// Component health status
    
    pub status: String,
    /// Response time in milliseconds
    
    pub response_time_ms: u64,
    /// Optional error message
    
    pub error: Option<String>,
}

/// Error response
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct ErrorResponse {
    /// Error code
    
    pub code: String,
    /// Error message
    
    pub message: String,
    /// Error details
    
    pub details: Option<HashMap<String, serde_json::Value>>,
    /// Timestamp
    
    pub timestamp: DateTime<Utc>,
    /// Request ID for tracing
    
    pub request_id: String,
}