mockforge-ui 0.3.88

Admin UI for MockForge - web-based interface for managing mock servers
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
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
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
//! Data models for the admin UI

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

/// Server status information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerStatus {
    /// Server type (HTTP, WebSocket, gRPC)
    pub server_type: String,
    /// Server address
    pub address: Option<String>,
    /// Whether server is running
    pub running: bool,
    /// Start time
    pub start_time: Option<chrono::DateTime<chrono::Utc>>,
    /// Uptime in seconds
    pub uptime_seconds: Option<u64>,
    /// Number of active connections
    pub active_connections: u64,
    /// Total requests served
    pub total_requests: u64,
}

/// Route information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RouteInfo {
    /// HTTP method
    pub method: Option<String>,
    /// Route path
    pub path: String,
    /// Route priority
    pub priority: i32,
    /// Whether route has fixtures
    pub has_fixtures: bool,
    /// Latency profile
    pub latency_ms: Option<u64>,
    /// Request count
    pub request_count: u64,
    /// Last request time
    pub last_request: Option<chrono::DateTime<chrono::Utc>>,
    /// Error count
    pub error_count: u64,
}

/// Request log entry
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RequestLog {
    /// Request ID
    pub id: String,
    /// Timestamp
    pub timestamp: chrono::DateTime<chrono::Utc>,
    /// HTTP method
    pub method: String,
    /// Request path
    pub path: String,
    /// Response status code
    pub status_code: u16,
    /// Response time in milliseconds
    pub response_time_ms: u64,
    /// Client IP address
    pub client_ip: Option<String>,
    /// User agent
    pub user_agent: Option<String>,
    /// Request headers (filtered)
    pub headers: HashMap<String, String>,
    /// Response size in bytes
    pub response_size_bytes: u64,
    /// Error message (if any)
    pub error_message: Option<String>,
}

/// System information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SystemInfo {
    /// MockForge version
    pub version: String,
    /// Uptime in seconds
    pub uptime_seconds: u64,
    /// Memory usage in MB
    pub memory_usage_mb: u64,
    /// CPU usage percentage
    pub cpu_usage_percent: f64,
    /// Number of active threads
    pub active_threads: usize,
    /// Total routes configured
    pub total_routes: usize,
    /// Total fixtures available
    pub total_fixtures: usize,
}

/// Latency profile configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LatencyProfile {
    /// Profile name
    pub name: String,
    /// Base latency in milliseconds
    pub base_ms: u64,
    /// Jitter range in milliseconds
    pub jitter_ms: u64,
    /// Tag-based overrides
    pub tag_overrides: HashMap<String, u64>,
}

/// Fault injection configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FaultConfig {
    /// Whether fault injection is enabled
    pub enabled: bool,
    /// Failure rate (0.0 to 1.0)
    pub failure_rate: f64,
    /// HTTP status codes for failures
    pub status_codes: Vec<u16>,
    /// Current active failures
    pub active_failures: u64,
}

/// Proxy configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProxyConfig {
    /// Whether proxy is enabled
    pub enabled: bool,
    /// Upstream URL
    pub upstream_url: Option<String>,
    /// Request timeout seconds
    pub timeout_seconds: u64,
    /// Total requests proxied
    pub requests_proxied: u64,
}

/// Bandwidth configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BandwidthConfig {
    /// Whether bandwidth throttling is enabled
    pub enabled: bool,
    /// Maximum bandwidth in bytes per second
    pub max_bytes_per_sec: u64,
    /// Burst capacity in bytes
    pub burst_capacity_bytes: u64,
    /// Tag-based overrides
    pub tag_overrides: HashMap<String, u64>,
}

/// Burst loss configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BurstLossConfig {
    /// Whether burst loss is enabled
    pub enabled: bool,
    /// Probability of entering burst (0.0 to 1.0)
    pub burst_probability: f64,
    /// Duration of burst in milliseconds
    pub burst_duration_ms: u64,
    /// Loss rate during burst (0.0 to 1.0)
    pub loss_rate_during_burst: f64,
    /// Recovery time between bursts in milliseconds
    pub recovery_time_ms: u64,
    /// Tag-based overrides
    pub tag_overrides: HashMap<String, BurstLossOverride>,
}

/// Burst loss override for specific tags
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BurstLossOverride {
    pub burst_probability: f64,
    pub burst_duration_ms: u64,
    pub loss_rate_during_burst: f64,
    pub recovery_time_ms: u64,
}

/// Traffic shaping configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TrafficShapingConfig {
    /// Whether traffic shaping is enabled
    pub enabled: bool,
    /// Bandwidth configuration
    pub bandwidth: BandwidthConfig,
    /// Burst loss configuration
    pub burst_loss: BurstLossConfig,
}

/// Simple metrics data for admin dashboard
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SimpleMetricsData {
    /// Total requests served
    pub total_requests: u64,
    /// Active requests currently being processed
    pub active_requests: u64,
    /// Average response time in milliseconds
    pub average_response_time: f64,
    /// Error rate (0.0 to 1.0)
    pub error_rate: f64,
}

/// Dashboard system information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DashboardSystemInfo {
    /// Operating system
    pub os: String,
    /// Architecture
    pub arch: String,
    /// Uptime in seconds
    pub uptime: u64,
    /// Memory usage in bytes
    pub memory_usage: u64,
}

/// Dashboard data
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DashboardData {
    /// Server information
    pub server_info: ServerInfo,
    /// System information
    pub system_info: DashboardSystemInfo,
    /// Metrics data
    pub metrics: SimpleMetricsData,
    /// Server status information
    pub servers: Vec<ServerStatus>,
    /// Recent logs
    pub recent_logs: Vec<RequestLog>,
    /// System information (for JS compatibility)
    pub system: SystemInfo,
}

/// API response wrapper
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiResponse<T> {
    /// Whether request was successful
    pub success: bool,
    /// Response data
    pub data: Option<T>,
    /// Error message (if any)
    pub error: Option<String>,
    /// Response timestamp
    pub timestamp: chrono::DateTime<chrono::Utc>,
}

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

    /// Create an error response
    pub fn error(message: String) -> Self {
        Self {
            success: false,
            data: None,
            error: Some(message),
            timestamp: chrono::Utc::now(),
        }
    }
}

/// Configuration update request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConfigUpdate {
    /// Configuration type
    pub config_type: String,
    /// Configuration data
    pub data: serde_json::Value,
}

/// Route management request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RouteUpdate {
    /// Route path
    pub path: String,
    /// HTTP method (optional)
    pub method: Option<String>,
    /// Update operation
    pub operation: String,
    /// Update data
    pub data: Option<serde_json::Value>,
}

/// Log filter options
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogFilter {
    /// Filter by HTTP method
    pub method: Option<String>,
    /// Filter by path pattern
    pub path_pattern: Option<String>,
    /// Filter by status code
    pub status_code: Option<u16>,
    /// Filter by time range (hours ago)
    pub hours_ago: Option<u64>,
    /// Maximum number of results
    pub limit: Option<usize>,
}

impl Default for LogFilter {
    fn default() -> Self {
        Self {
            method: None,
            path_pattern: None,
            status_code: None,
            hours_ago: Some(24),
            limit: Some(100),
        }
    }
}

/// Performance metrics data with detailed percentile analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetricsData {
    /// Request count by endpoint
    pub requests_by_endpoint: HashMap<String, u64>,
    /// Response time percentiles (p50, p75, p90, p95, p99, p999)
    pub response_time_percentiles: HashMap<String, u64>,
    /// Per-endpoint percentiles for detailed analysis
    #[serde(skip_serializing_if = "Option::is_none")]
    pub endpoint_percentiles: Option<HashMap<String, HashMap<String, u64>>>,
    /// Latency over time (time-series data)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub latency_over_time: Option<Vec<(chrono::DateTime<chrono::Utc>, u64)>>,
    /// Error rate by endpoint
    pub error_rate_by_endpoint: HashMap<String, f64>,
    /// Memory usage over time
    pub memory_usage_over_time: Vec<(chrono::DateTime<chrono::Utc>, u64)>,
    /// CPU usage over time
    pub cpu_usage_over_time: Vec<(chrono::DateTime<chrono::Utc>, f64)>,
}

/// Validation settings
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationSettings {
    /// Validation mode: "enforce", "warn", or "off"
    pub mode: String,
    /// Whether to aggregate errors
    pub aggregate_errors: bool,
    /// Whether to validate responses
    pub validate_responses: bool,
    /// Per-route validation overrides
    pub overrides: HashMap<String, String>,
}

/// Validation update request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationUpdate {
    /// Validation mode
    pub mode: String,
    /// Whether to aggregate errors
    pub aggregate_errors: bool,
    /// Whether to validate responses
    pub validate_responses: bool,
    /// Per-route validation overrides
    pub overrides: Option<HashMap<String, String>>,
}

/// Log entry for admin UI
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LogEntry {
    /// Request timestamp
    pub timestamp: chrono::DateTime<chrono::Utc>,
    /// HTTP status code
    pub status: u16,
    /// HTTP method
    pub method: String,
    /// Request URL/path
    pub url: String,
    /// Response time in milliseconds
    pub response_time: u64,
    /// Response size in bytes
    pub size: u64,
}

/// Health check response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthCheck {
    /// Overall health status
    pub status: String,
    /// Individual service health
    pub services: HashMap<String, String>,
    /// Last health check time
    pub last_check: chrono::DateTime<chrono::Utc>,
    /// Any health issues
    pub issues: Vec<String>,
}

impl HealthCheck {
    /// Create a healthy status
    pub fn healthy() -> Self {
        Self {
            status: "healthy".to_string(),
            services: HashMap::new(),
            last_check: chrono::Utc::now(),
            issues: Vec::new(),
        }
    }

    /// Create an unhealthy status
    pub fn unhealthy(issues: Vec<String>) -> Self {
        Self {
            status: "unhealthy".to_string(),
            services: HashMap::new(),
            last_check: chrono::Utc::now(),
            issues,
        }
    }

    /// Add service status
    pub fn with_service(mut self, name: String, status: String) -> Self {
        self.services.insert(name, status);
        self
    }
}

/// Workspace summary information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkspaceSummary {
    /// Workspace ID
    pub id: String,
    /// Workspace name
    pub name: String,
    /// Description
    pub description: Option<String>,
    /// Whether this is the active workspace
    pub active: bool,
    /// Number of folders
    pub folder_count: usize,
    /// Number of requests
    pub request_count: usize,
    /// Created timestamp
    pub created_at: chrono::DateTime<chrono::Utc>,
    /// Updated timestamp
    pub updated_at: chrono::DateTime<chrono::Utc>,
}

/// Folder summary information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FolderSummary {
    /// Folder ID
    pub id: String,
    /// Folder name
    pub name: String,
    /// Description
    pub description: Option<String>,
    /// Parent folder ID (None if root)
    pub parent_id: Option<String>,
    /// Number of subfolders
    pub subfolder_count: usize,
    /// Number of requests
    pub request_count: usize,
    /// Created timestamp
    pub created_at: chrono::DateTime<chrono::Utc>,
    /// Updated timestamp
    pub updated_at: chrono::DateTime<chrono::Utc>,
}

/// Request summary information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RequestSummary {
    /// Request ID
    pub id: String,
    /// Request name
    pub name: String,
    /// Description
    pub description: Option<String>,
    /// HTTP method
    pub method: String,
    /// Request path
    pub path: String,
    /// Response status code
    pub status_code: u16,
    /// Created timestamp
    pub created_at: chrono::DateTime<chrono::Utc>,
    /// Updated timestamp
    pub updated_at: chrono::DateTime<chrono::Utc>,
}

/// Workspace detailed information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkspaceDetail {
    /// Workspace summary
    pub summary: WorkspaceSummary,
    /// Root folders
    pub folders: Vec<FolderSummary>,
    /// Root requests
    pub requests: Vec<RequestSummary>,
}

/// Folder detailed information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FolderDetail {
    /// Folder summary
    pub summary: FolderSummary,
    /// Subfolders
    pub subfolders: Vec<FolderSummary>,
    /// Requests in this folder
    pub requests: Vec<RequestSummary>,
}

/// Create workspace request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateWorkspaceRequest {
    /// Workspace name
    pub name: String,
    /// Description (optional)
    pub description: Option<String>,
}

/// Create folder request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateFolderRequest {
    /// Folder name
    pub name: String,
    /// Description (optional)
    pub description: Option<String>,
    /// Parent folder ID (optional)
    pub parent_id: Option<String>,
}

/// Create request request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateRequestRequest {
    /// Request name
    pub name: String,
    /// Description (optional)
    pub description: Option<String>,
    /// HTTP method
    pub method: String,
    /// Request path
    pub path: String,
    /// Response status code
    pub status_code: Option<u16>,
    /// Response body
    pub response_body: Option<String>,
    /// Folder ID (optional)
    pub folder_id: Option<String>,
}

/// Import to workspace request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImportToWorkspaceRequest {
    /// Import format (postman, insomnia, curl)
    pub format: String,
    /// Import data (file content or URL)
    pub data: String,
    /// Folder ID to import into (optional)
    pub folder_id: Option<String>,
    /// Whether to create folders from import structure
    pub create_folders: Option<bool>,
    /// Indices of routes to import (for selective import)
    pub selected_routes: Option<Vec<usize>>,
}

/// Export workspaces request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExportWorkspacesRequest {
    /// Workspace IDs to export
    pub workspace_ids: Vec<String>,
}

/// Workspace export data
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkspaceExportData {
    /// Exported workspaces
    pub workspaces: Vec<mockforge_core::Workspace>,
    /// Export version
    pub version: String,
    /// Export timestamp
    pub exported_at: chrono::DateTime<chrono::Utc>,
    /// Exporter version
    pub exporter_version: String,
}

/// Environment color information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnvironmentColor {
    /// Hex color code (e.g., "#FF5733")
    pub hex: String,
    /// Optional color name for accessibility
    pub name: Option<String>,
}

/// Environment summary information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnvironmentSummary {
    /// Environment ID
    pub id: String,
    /// Environment name
    pub name: String,
    /// Description
    pub description: Option<String>,
    /// Color for visual distinction
    pub color: Option<EnvironmentColor>,
    /// Number of variables
    pub variable_count: usize,
    /// Whether this is the active environment
    pub active: bool,
    /// Whether this is the global environment
    pub is_global: bool,
    /// Created timestamp
    pub created_at: chrono::DateTime<chrono::Utc>,
    /// Updated timestamp
    pub updated_at: chrono::DateTime<chrono::Utc>,
}

/// Environment variable information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnvironmentVariable {
    /// Variable name
    pub name: String,
    /// Variable value
    pub value: String,
    /// Whether this variable is from the global environment
    pub from_global: bool,
}

/// Create environment request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateEnvironmentRequest {
    /// Environment name
    pub name: String,
    /// Description
    pub description: Option<String>,
}

/// Update environment request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateEnvironmentRequest {
    /// Environment name
    pub name: Option<String>,
    /// Description
    pub description: Option<String>,
    /// Color
    pub color: Option<EnvironmentColor>,
}

/// Set variable request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SetVariableRequest {
    /// Variable name
    pub name: String,
    /// Variable value
    pub value: String,
}

/// Directory sync configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SyncConfig {
    /// Enable directory syncing for this workspace
    pub enabled: bool,
    /// Target directory for sync (relative or absolute path)
    pub target_directory: Option<String>,
    /// Directory structure to use (flat, nested, grouped)
    pub directory_structure: SyncDirectoryStructure,
    /// Auto-sync direction (one-way workspace→directory, bidirectional, or manual)
    pub sync_direction: SyncDirection,
    /// Whether to include metadata files
    pub include_metadata: bool,
    /// Filesystem monitoring enabled for real-time sync
    pub realtime_monitoring: bool,
    /// Custom filename pattern for exported files
    pub filename_pattern: String,
    /// Regular expression for excluding workspaces/requests
    pub exclude_pattern: Option<String>,
    /// Force overwrite existing files during sync
    pub force_overwrite: bool,
}

/// Directory structure options for sync
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SyncDirectoryStructure {
    /// All workspaces in flat structure: workspace-name.yaml
    Flat,
    /// Nested by workspace: workspaces/{name}/workspace.yaml + requests/
    Nested,
    /// Grouped by type: requests/, responses/, metadata/
    Grouped,
}

/// Sync direction options
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SyncDirection {
    /// Manual sync only (one-off operations)
    Manual,
    /// One-way: workspace changes sync silently to directory
    WorkspaceToDirectory,
    /// Bidirectional: changes in either direction trigger sync
    Bidirectional,
}

impl From<mockforge_core::workspace::SyncDirection> for SyncDirection {
    fn from(core: mockforge_core::workspace::SyncDirection) -> Self {
        match core {
            mockforge_core::workspace::SyncDirection::Manual => Self::Manual,
            mockforge_core::workspace::SyncDirection::WorkspaceToDirectory => {
                Self::WorkspaceToDirectory
            }
            mockforge_core::workspace::SyncDirection::Bidirectional => Self::Bidirectional,
        }
    }
}

/// Sync status information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SyncStatus {
    /// Workspace ID
    pub workspace_id: String,
    /// Whether sync is enabled
    pub enabled: bool,
    /// Target directory
    pub target_directory: Option<String>,
    /// Current sync direction
    pub sync_direction: SyncDirection,
    /// Whether real-time monitoring is active
    pub realtime_monitoring: bool,
    /// Last sync timestamp
    pub last_sync: Option<chrono::DateTime<chrono::Utc>>,
    /// Sync status message
    pub status: String,
}

/// Sync change information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SyncChange {
    /// Change type
    pub change_type: String,
    /// File path
    pub path: String,
    /// Change description
    pub description: String,
    /// Whether this change requires confirmation
    pub requires_confirmation: bool,
}

/// Configure sync request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConfigureSyncRequest {
    /// Target directory
    pub target_directory: String,
    /// Sync direction
    pub sync_direction: SyncDirection,
    /// Enable real-time monitoring
    pub realtime_monitoring: bool,
    /// Directory structure
    pub directory_structure: Option<SyncDirectoryStructure>,
    /// Filename pattern
    pub filename_pattern: Option<String>,
}

/// Confirm sync changes request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConfirmSyncChangesRequest {
    /// Workspace ID
    pub workspace_id: String,
    /// Changes to confirm
    pub changes: Vec<SyncChange>,
    /// Whether to apply all changes
    pub apply_all: bool,
}

/// Autocomplete suggestion
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AutocompleteSuggestion {
    /// Suggestion text
    pub text: String,
    /// Suggestion type (e.g., "variable", "template")
    pub kind: String,
    /// Optional description
    pub description: Option<String>,
}

/// Autocomplete request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AutocompleteRequest {
    /// Current input text
    pub input: String,
    /// Cursor position in the text
    pub cursor_position: usize,
    /// Context type (e.g., "header", "body", "url")
    pub context: Option<String>,
}

/// Autocomplete response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AutocompleteResponse {
    /// List of suggestions
    pub suggestions: Vec<AutocompleteSuggestion>,
    /// Start position of the token being completed
    pub start_position: usize,
    /// End position of the token being completed
    pub end_position: usize,
}

/// Time series data point
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimeSeriesPoint {
    /// Timestamp
    pub timestamp: chrono::DateTime<chrono::Utc>,
    /// Value
    pub value: f64,
}

/// Time series data
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimeSeriesData {
    /// Data points
    pub points: Vec<TimeSeriesPoint>,
    /// Metric name
    pub metric: String,
}

/// Restart status
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RestartStatus {
    /// Whether restart is in progress
    pub restarting: bool,
    /// Restart progress (0.0 to 1.0)
    pub progress: f64,
    /// Status message
    pub message: String,
}

/// Smoke test result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SmokeTestResult {
    /// Test name
    pub test_name: String,
    /// Whether test passed
    pub passed: bool,
    /// Response time in milliseconds
    pub response_time_ms: Option<u64>,
    /// Error message (if failed)
    pub error_message: Option<String>,
}

/// Smoke test context
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SmokeTestContext {
    /// Test suite name
    pub suite_name: String,
    /// Total tests
    pub total_tests: usize,
    /// Passed tests
    pub passed_tests: usize,
    /// Failed tests
    pub failed_tests: usize,
    /// Start time
    pub start_time: chrono::DateTime<chrono::Utc>,
    /// End time
    pub end_time: Option<chrono::DateTime<chrono::Utc>>,
}

/// Configuration state
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConfigurationState {
    /// Whether configuration is valid
    pub valid: bool,
    /// Configuration errors
    pub errors: Vec<String>,
    /// Configuration warnings
    pub warnings: Vec<String>,
}

/// Import history entry
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImportHistoryEntry {
    /// Entry ID
    pub id: String,
    /// Import format
    pub format: String,
    /// Import timestamp
    pub timestamp: chrono::DateTime<chrono::Utc>,
    /// Number of routes imported
    pub routes_count: usize,
    /// Number of variables imported
    pub variables_count: usize,
    /// Number of warnings
    pub warnings_count: usize,
    /// Whether import was successful
    pub success: bool,
    /// Filename (if applicable)
    pub filename: Option<String>,
    /// Environment name
    pub environment: Option<String>,
    /// Base URL
    pub base_url: Option<String>,
    /// Error message (if failed)
    pub error_message: Option<String>,
}

/// Fixture information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FixtureInfo {
    /// Fixture ID
    pub id: String,
    /// Fixture name
    pub name: String,
    /// Fixture path
    pub path: String,
    /// File size in bytes
    pub size_bytes: u64,
    /// Last modified timestamp
    pub last_modified: chrono::DateTime<chrono::Utc>,
    /// Content type
    pub content_type: Option<String>,
}

/// Fixture delete request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FixtureDeleteRequest {
    /// Fixture ID to delete
    pub fixture_id: String,
}

/// Fixture bulk delete request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FixtureBulkDeleteRequest {
    /// Fixture IDs to delete
    pub fixture_ids: Vec<String>,
}

/// Fixture bulk delete result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FixtureBulkDeleteResult {
    /// Successfully deleted fixture IDs
    pub deleted: Vec<String>,
    /// Failed deletions with error messages
    pub failed: HashMap<String, String>,
}

/// Import route
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImportRoute {
    /// HTTP method
    pub method: String,
    /// Route path
    pub path: String,
    /// Request headers
    pub headers: HashMap<String, String>,
    /// Request body
    pub body: Option<String>,
    /// Expected response
    pub response: ImportResponse,
}

/// Import response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImportResponse {
    /// HTTP status code
    pub status: u16,
    /// Response headers
    pub headers: HashMap<String, String>,
    /// Response body
    pub body: serde_json::Value,
}

/// Import result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImportResult {
    /// Imported routes
    pub routes: Vec<ImportRoute>,
    /// Import warnings
    pub warnings: Vec<String>,
    /// Import errors
    pub errors: Vec<String>,
}

/// Insomnia import result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InsomniaImportResult {
    /// Imported routes
    pub routes: Vec<ImportRoute>,
    /// Environment variables
    pub variables: HashMap<String, String>,
    /// Import warnings
    pub warnings: Vec<String>,
}

/// Server information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerInfo {
    /// Server version
    pub version: String,
    /// Build timestamp
    pub build_time: String,
    /// Git SHA
    pub git_sha: String,
    /// HTTP server address (optional)
    pub http_server: Option<String>,
    /// WebSocket server address (optional)
    pub ws_server: Option<String>,
    /// gRPC server address (optional)
    pub grpc_server: Option<String>,
    /// GraphQL server address (optional)
    pub graphql_server: Option<String>,
    /// Whether API endpoints are enabled
    pub api_enabled: bool,
    /// Admin server port
    pub admin_port: u16,
}

#[cfg(test)]
mod tests {
    use super::*;

    // ==================== ApiResponse Tests ====================

    #[test]
    fn test_api_response_success() {
        let data = "test data".to_string();
        let response = ApiResponse::success(data.clone());

        assert!(response.success);
        assert_eq!(response.data, Some(data));
        assert!(response.error.is_none());
    }

    #[test]
    fn test_api_response_error() {
        let error_msg = "Something went wrong".to_string();
        let response: ApiResponse<String> = ApiResponse::error(error_msg.clone());

        assert!(!response.success);
        assert!(response.data.is_none());
        assert_eq!(response.error, Some(error_msg));
    }

    #[test]
    fn test_api_response_success_with_int() {
        let response = ApiResponse::success(42);
        assert!(response.success);
        assert_eq!(response.data, Some(42));
    }

    // ==================== HealthCheck Tests ====================

    #[test]
    fn test_health_check_healthy() {
        let health = HealthCheck::healthy();

        assert_eq!(health.status, "healthy");
        assert!(health.issues.is_empty());
        assert!(health.services.is_empty());
    }

    #[test]
    fn test_health_check_unhealthy() {
        let issues = vec!["Database down".to_string(), "Cache error".to_string()];
        let health = HealthCheck::unhealthy(issues.clone());

        assert_eq!(health.status, "unhealthy");
        assert_eq!(health.issues, issues);
    }

    #[test]
    fn test_health_check_with_service() {
        let health = HealthCheck::healthy()
            .with_service("http".to_string(), "running".to_string())
            .with_service("grpc".to_string(), "running".to_string());

        assert_eq!(health.services.len(), 2);
        assert_eq!(health.services.get("http"), Some(&"running".to_string()));
    }

    // ==================== LogFilter Tests ====================

    #[test]
    fn test_log_filter_default() {
        let filter = LogFilter::default();

        assert!(filter.method.is_none());
        assert!(filter.path_pattern.is_none());
        assert_eq!(filter.hours_ago, Some(24));
        assert_eq!(filter.limit, Some(100));
    }

    #[test]
    fn test_log_filter_custom() {
        let filter = LogFilter {
            method: Some("POST".to_string()),
            path_pattern: Some("/api/.*".to_string()),
            status_code: Some(200),
            hours_ago: Some(48),
            limit: Some(500),
        };

        assert_eq!(filter.method.as_deref(), Some("POST"));
        assert_eq!(filter.status_code, Some(200));
    }

    // ==================== ServerStatus Tests ====================

    #[test]
    fn test_server_status() {
        let status = ServerStatus {
            server_type: "HTTP".to_string(),
            address: Some("127.0.0.1:3000".to_string()),
            running: true,
            start_time: Some(chrono::Utc::now()),
            uptime_seconds: Some(3600),
            active_connections: 10,
            total_requests: 1000,
        };

        assert_eq!(status.server_type, "HTTP");
        assert!(status.running);
        assert_eq!(status.active_connections, 10);
    }

    #[test]
    fn test_server_status_serialization() {
        let status = ServerStatus {
            server_type: "gRPC".to_string(),
            address: None,
            running: false,
            start_time: None,
            uptime_seconds: None,
            active_connections: 0,
            total_requests: 0,
        };

        let json = serde_json::to_string(&status).unwrap();
        let deserialized: ServerStatus = serde_json::from_str(&json).unwrap();
        assert_eq!(deserialized.server_type, "gRPC");
    }

    // ==================== RouteInfo Tests ====================

    #[test]
    fn test_route_info() {
        let route = RouteInfo {
            method: Some("GET".to_string()),
            path: "/api/users".to_string(),
            priority: 100,
            has_fixtures: true,
            latency_ms: Some(50),
            request_count: 500,
            last_request: None,
            error_count: 5,
        };

        assert_eq!(route.method, Some("GET".to_string()));
        assert_eq!(route.path, "/api/users");
        assert!(route.has_fixtures);
    }

    #[test]
    fn test_route_info_clone() {
        let route = RouteInfo {
            method: Some("POST".to_string()),
            path: "/api/items".to_string(),
            priority: 50,
            has_fixtures: false,
            latency_ms: None,
            request_count: 0,
            last_request: None,
            error_count: 0,
        };

        let cloned = route.clone();
        assert_eq!(cloned.path, route.path);
        assert_eq!(cloned.priority, route.priority);
    }

    // ==================== RequestLog Tests ====================

    #[test]
    fn test_request_log() {
        let log = RequestLog {
            id: "req-123".to_string(),
            timestamp: chrono::Utc::now(),
            method: "GET".to_string(),
            path: "/api/data".to_string(),
            status_code: 200,
            response_time_ms: 45,
            client_ip: Some("192.168.1.1".to_string()),
            user_agent: Some("curl/7.64.0".to_string()),
            headers: HashMap::new(),
            response_size_bytes: 1024,
            error_message: None,
        };

        assert_eq!(log.id, "req-123");
        assert_eq!(log.status_code, 200);
    }

    // ==================== SystemInfo Tests ====================

    #[test]
    fn test_system_info() {
        let info = SystemInfo {
            version: "0.3.8".to_string(),
            uptime_seconds: 86400,
            memory_usage_mb: 256,
            cpu_usage_percent: 25.5,
            active_threads: 8,
            total_routes: 50,
            total_fixtures: 100,
        };

        assert_eq!(info.version, "0.3.8");
        assert_eq!(info.total_routes, 50);
    }

    // ==================== LatencyProfile Tests ====================

    #[test]
    fn test_latency_profile() {
        let profile = LatencyProfile {
            name: "slow_network".to_string(),
            base_ms: 200,
            jitter_ms: 50,
            tag_overrides: HashMap::from([("critical".to_string(), 50)]),
        };

        assert_eq!(profile.name, "slow_network");
        assert_eq!(profile.base_ms, 200);
    }

    // ==================== FaultConfig Tests ====================

    #[test]
    fn test_fault_config() {
        let config = FaultConfig {
            enabled: true,
            failure_rate: 0.1,
            status_codes: vec![500, 503],
            active_failures: 5,
        };

        assert!(config.enabled);
        assert!(config.failure_rate > 0.0);
        assert_eq!(config.status_codes.len(), 2);
    }

    // ==================== ProxyConfig Tests ====================

    #[test]
    fn test_proxy_config() {
        let config = ProxyConfig {
            enabled: true,
            upstream_url: Some("https://api.example.com".to_string()),
            timeout_seconds: 30,
            requests_proxied: 1000,
        };

        assert!(config.enabled);
        assert!(config.upstream_url.is_some());
    }

    // ==================== BandwidthConfig Tests ====================

    #[test]
    fn test_bandwidth_config() {
        let config = BandwidthConfig {
            enabled: true,
            max_bytes_per_sec: 1_000_000,
            burst_capacity_bytes: 10_000,
            tag_overrides: HashMap::new(),
        };

        assert!(config.enabled);
        assert_eq!(config.max_bytes_per_sec, 1_000_000);
    }

    // ==================== BurstLossConfig Tests ====================

    #[test]
    fn test_burst_loss_config() {
        let config = BurstLossConfig {
            enabled: false,
            burst_probability: 0.05,
            burst_duration_ms: 1000,
            loss_rate_during_burst: 0.3,
            recovery_time_ms: 5000,
            tag_overrides: HashMap::new(),
        };

        assert!(!config.enabled);
        assert_eq!(config.burst_duration_ms, 1000);
    }

    // ==================== SimpleMetricsData Tests ====================

    #[test]
    fn test_simple_metrics_data() {
        let metrics = SimpleMetricsData {
            total_requests: 10000,
            active_requests: 5,
            average_response_time: 45.5,
            error_rate: 0.02,
        };

        assert_eq!(metrics.total_requests, 10000);
        assert!(metrics.error_rate < 0.05);
    }

    // ==================== ConfigUpdate Tests ====================

    #[test]
    fn test_config_update() {
        let update = ConfigUpdate {
            config_type: "latency".to_string(),
            data: serde_json::json!({"base_ms": 100}),
        };

        assert_eq!(update.config_type, "latency");
    }

    // ==================== RouteUpdate Tests ====================

    #[test]
    fn test_route_update() {
        let update = RouteUpdate {
            path: "/api/users".to_string(),
            method: Some("POST".to_string()),
            operation: "create".to_string(),
            data: Some(serde_json::json!({"fixture": "user.json"})),
        };

        assert_eq!(update.path, "/api/users");
        assert_eq!(update.operation, "create");
    }

    // ==================== ValidationSettings Tests ====================

    #[test]
    fn test_validation_settings() {
        let settings = ValidationSettings {
            mode: "enforce".to_string(),
            aggregate_errors: true,
            validate_responses: true,
            overrides: HashMap::new(),
        };

        assert_eq!(settings.mode, "enforce");
        assert!(settings.validate_responses);
    }

    // ==================== LogEntry Tests ====================

    #[test]
    fn test_log_entry() {
        let entry = LogEntry {
            timestamp: chrono::Utc::now(),
            status: 200,
            method: "GET".to_string(),
            url: "/api/test".to_string(),
            response_time: 50,
            size: 1024,
        };

        assert_eq!(entry.status, 200);
        assert_eq!(entry.method, "GET");
    }

    // ==================== WorkspaceSummary Tests ====================

    #[test]
    fn test_workspace_summary() {
        let summary = WorkspaceSummary {
            id: "ws-123".to_string(),
            name: "My Workspace".to_string(),
            description: Some("Test workspace".to_string()),
            active: true,
            folder_count: 5,
            request_count: 20,
            created_at: chrono::Utc::now(),
            updated_at: chrono::Utc::now(),
        };

        assert_eq!(summary.name, "My Workspace");
        assert!(summary.active);
    }

    // ==================== FolderSummary Tests ====================

    #[test]
    fn test_folder_summary() {
        let folder = FolderSummary {
            id: "folder-123".to_string(),
            name: "API Tests".to_string(),
            description: None,
            parent_id: None,
            subfolder_count: 3,
            request_count: 10,
            created_at: chrono::Utc::now(),
            updated_at: chrono::Utc::now(),
        };

        assert_eq!(folder.name, "API Tests");
        assert!(folder.parent_id.is_none());
    }

    // ==================== RequestSummary Tests ====================

    #[test]
    fn test_request_summary() {
        let request = RequestSummary {
            id: "req-123".to_string(),
            name: "Get Users".to_string(),
            description: Some("Fetch all users".to_string()),
            method: "GET".to_string(),
            path: "/api/users".to_string(),
            status_code: 200,
            created_at: chrono::Utc::now(),
            updated_at: chrono::Utc::now(),
        };

        assert_eq!(request.method, "GET");
        assert_eq!(request.status_code, 200);
    }

    // ==================== CreateWorkspaceRequest Tests ====================

    #[test]
    fn test_create_workspace_request() {
        let request = CreateWorkspaceRequest {
            name: "New Workspace".to_string(),
            description: Some("A new workspace".to_string()),
        };

        assert_eq!(request.name, "New Workspace");
    }

    // ==================== CreateFolderRequest Tests ====================

    #[test]
    fn test_create_folder_request() {
        let request = CreateFolderRequest {
            name: "New Folder".to_string(),
            description: None,
            parent_id: Some("parent-123".to_string()),
        };

        assert_eq!(request.name, "New Folder");
        assert!(request.parent_id.is_some());
    }

    // ==================== SyncConfig Tests ====================

    #[test]
    fn test_sync_direction_conversion() {
        let manual = mockforge_core::workspace::SyncDirection::Manual;
        let ui_manual: SyncDirection = manual.into();
        assert!(matches!(ui_manual, SyncDirection::Manual));
    }

    #[test]
    fn test_sync_direction_workspace_to_directory() {
        let dir = mockforge_core::workspace::SyncDirection::WorkspaceToDirectory;
        let ui_dir: SyncDirection = dir.into();
        assert!(matches!(ui_dir, SyncDirection::WorkspaceToDirectory));
    }

    #[test]
    fn test_sync_direction_bidirectional() {
        let bidir = mockforge_core::workspace::SyncDirection::Bidirectional;
        let ui_bidir: SyncDirection = bidir.into();
        assert!(matches!(ui_bidir, SyncDirection::Bidirectional));
    }

    // ==================== EnvironmentColor Tests ====================

    #[test]
    fn test_environment_color() {
        let color = EnvironmentColor {
            hex: "#FF5733".to_string(),
            name: Some("Orange".to_string()),
        };

        assert_eq!(color.hex, "#FF5733");
        assert_eq!(color.name, Some("Orange".to_string()));
    }

    #[test]
    fn test_environment_color_without_name() {
        let color = EnvironmentColor {
            hex: "#00FF00".to_string(),
            name: None,
        };

        assert_eq!(color.hex, "#00FF00");
        assert!(color.name.is_none());
    }

    // ==================== EnvironmentSummary Tests ====================

    #[test]
    fn test_environment_summary() {
        let env = EnvironmentSummary {
            id: "env-123".to_string(),
            name: "Production".to_string(),
            description: Some("Production environment".to_string()),
            color: Some(EnvironmentColor {
                hex: "#FF0000".to_string(),
                name: Some("Red".to_string()),
            }),
            variable_count: 10,
            active: true,
            is_global: false,
            created_at: chrono::Utc::now(),
            updated_at: chrono::Utc::now(),
        };

        assert_eq!(env.name, "Production");
        assert!(env.active);
        assert!(!env.is_global);
    }

    // ==================== AutocompleteSuggestion Tests ====================

    #[test]
    fn test_autocomplete_suggestion() {
        let suggestion = AutocompleteSuggestion {
            text: "{{base_url}}".to_string(),
            kind: "variable".to_string(),
            description: Some("Base URL variable".to_string()),
        };

        assert_eq!(suggestion.kind, "variable");
    }

    // ==================== TimeSeriesPoint Tests ====================

    #[test]
    fn test_time_series_point() {
        let point = TimeSeriesPoint {
            timestamp: chrono::Utc::now(),
            value: 123.45,
        };

        assert!((point.value - 123.45).abs() < f64::EPSILON);
    }

    // ==================== RestartStatus Tests ====================

    #[test]
    fn test_restart_status() {
        let status = RestartStatus {
            restarting: true,
            progress: 0.5,
            message: "Restarting services...".to_string(),
        };

        assert!(status.restarting);
        assert!((status.progress - 0.5).abs() < f64::EPSILON);
    }

    // ==================== SmokeTestResult Tests ====================

    #[test]
    fn test_smoke_test_result_passed() {
        let result = SmokeTestResult {
            test_name: "Health Check".to_string(),
            passed: true,
            response_time_ms: Some(50),
            error_message: None,
        };

        assert!(result.passed);
        assert!(result.error_message.is_none());
    }

    #[test]
    fn test_smoke_test_result_failed() {
        let result = SmokeTestResult {
            test_name: "Database Connection".to_string(),
            passed: false,
            response_time_ms: None,
            error_message: Some("Connection timeout".to_string()),
        };

        assert!(!result.passed);
        assert!(result.error_message.is_some());
    }

    // ==================== ConfigurationState Tests ====================

    #[test]
    fn test_configuration_state_valid() {
        let state = ConfigurationState {
            valid: true,
            errors: vec![],
            warnings: vec!["Deprecated setting used".to_string()],
        };

        assert!(state.valid);
        assert!(state.errors.is_empty());
        assert!(!state.warnings.is_empty());
    }

    // ==================== ImportHistoryEntry Tests ====================

    #[test]
    fn test_import_history_entry() {
        let entry = ImportHistoryEntry {
            id: "import-123".to_string(),
            format: "postman".to_string(),
            timestamp: chrono::Utc::now(),
            routes_count: 25,
            variables_count: 5,
            warnings_count: 2,
            success: true,
            filename: Some("collection.json".to_string()),
            environment: Some("development".to_string()),
            base_url: Some("https://api.example.com".to_string()),
            error_message: None,
        };

        assert!(entry.success);
        assert_eq!(entry.routes_count, 25);
    }

    // ==================== FixtureInfo Tests ====================

    #[test]
    fn test_fixture_info() {
        let fixture = FixtureInfo {
            id: "fixture-123".to_string(),
            name: "users.json".to_string(),
            path: "/fixtures/users.json".to_string(),
            size_bytes: 2048,
            last_modified: chrono::Utc::now(),
            content_type: Some("application/json".to_string()),
        };

        assert_eq!(fixture.name, "users.json");
        assert_eq!(fixture.size_bytes, 2048);
    }

    // ==================== ImportRoute Tests ====================

    #[test]
    fn test_import_route() {
        let route = ImportRoute {
            method: "POST".to_string(),
            path: "/api/users".to_string(),
            headers: HashMap::from([("Content-Type".to_string(), "application/json".to_string())]),
            body: Some(r#"{"name": "test"}"#.to_string()),
            response: ImportResponse {
                status: 201,
                headers: HashMap::new(),
                body: serde_json::json!({"id": 1}),
            },
        };

        assert_eq!(route.method, "POST");
        assert_eq!(route.response.status, 201);
    }

    // ==================== ServerInfo Tests ====================

    #[test]
    fn test_server_info() {
        let info = ServerInfo {
            version: "0.3.8".to_string(),
            build_time: "2024-01-01T00:00:00Z".to_string(),
            git_sha: "abc123".to_string(),
            http_server: Some("0.0.0.0:3000".to_string()),
            ws_server: Some("0.0.0.0:3001".to_string()),
            grpc_server: None,
            graphql_server: None,
            api_enabled: true,
            admin_port: 8080,
        };

        assert_eq!(info.version, "0.3.8");
        assert!(info.api_enabled);
    }

    // ==================== Serialization Tests ====================

    #[test]
    fn test_log_filter_serialization() {
        let filter = LogFilter::default();
        let json = serde_json::to_string(&filter).unwrap();
        let deserialized: LogFilter = serde_json::from_str(&json).unwrap();

        assert_eq!(deserialized.hours_ago, filter.hours_ago);
    }

    #[test]
    fn test_health_check_serialization() {
        let health = HealthCheck::healthy().with_service("api".to_string(), "ok".to_string());
        let json = serde_json::to_string(&health).unwrap();
        let deserialized: HealthCheck = serde_json::from_str(&json).unwrap();

        assert_eq!(deserialized.status, "healthy");
    }
}