podman-lens 0.2.3

Version-aware Rust library for native Podman inspection and non-executing deployment planning
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
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
//! Typed, provenance-aware observations at the Podman native input boundary.
//!
//! This module deliberately models what the selected Podman service reported; it does not infer
//! desired deployment intent.  In particular, runtime-assigned addresses, local image IDs and
//! current lifecycle state never share a type with configured facts.  BoxFerry-facing adapters
//! must make an explicit mapping decision for every [`ObservationOrigin`].

use std::{
    collections::{BTreeMap, BTreeSet},
    fmt,
    net::IpAddr,
};

use crate::{
    Diagnostic, DiagnosticCode, InventoryFinding, JsonValueKind, ResourceEvidence, ResourceIdentity, ResourceKind,
    SensitiveEnvironmentValue,
};

/// The observation state of one native field.
///
/// `Absent` means that the reviewed wire field was absent or `null`; it never means malformed,
/// unavailable, inapplicable, or omitted from the native model.  Those states are represented
/// separately so an adapter cannot turn a decoder failure into an intentional empty value.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum ObservationField<T> {
    /// The field was absent from an otherwise decoded response.
    Absent,
    /// The field was decoded and carries its source disposition.
    Observed(ObservedValue<T>),
    /// The containing resource or section could not be acquired.
    Unavailable,
    /// The field was present but could not be decoded according to its reviewed shape.
    Malformed,
    /// The reviewed native version does not give this field a usable meaning.
    VersionInapplicable,
    /// The field has no meaning for this resource kind.
    NotApplicable,
    /// The field was deliberately retained only as bounded unmodelled metadata.
    Unmodelled(UnmodelledFieldId),
}

impl<T> fmt::Debug for ObservationField<T> {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_tuple("ObservationField")
            .field(&match self {
                Self::Absent => "absent",
                Self::Observed(_) => "observed",
                Self::Unavailable => "unavailable",
                Self::Malformed => "malformed",
                Self::VersionInapplicable => "version_inapplicable",
                Self::NotApplicable => "not_applicable",
                Self::Unmodelled(id) => id.as_str(),
            })
            .finish()
    }
}

impl<T> ObservationField<T> {
    /// Returns the observed value only when the field decoded successfully.
    #[must_use]
    pub const fn observed(&self) -> Option<&ObservedValue<T>> {
        match self {
            Self::Observed(value) => Some(value),
            _ => None,
        }
    }

    /// Returns whether this field contains a usable observation.
    #[must_use]
    pub const fn is_observed(&self) -> bool {
        matches!(self, Self::Observed(_))
    }

    /// Returns whether the native field was present but did not match its reviewed shape.
    #[must_use]
    pub const fn is_malformed(&self) -> bool {
        matches!(self, Self::Malformed)
    }
}

/// Provenance that prevents observed runtime facts from becoming desired intent accidentally.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ObservationOrigin {
    /// An explicit setting declared in the native resource configuration.
    Configured,
    /// A native effective value that may incorporate Podman defaults.
    Effective,
    /// A value allocated by the runtime, such as an address or a live state.
    RuntimeAssigned,
    /// A local resolver result, such as a resolved image ID.
    LocalResolution,
}

/// A successfully decoded value and its non-promotable provenance.
#[derive(Clone, Eq, PartialEq)]
pub struct ObservedValue<T> {
    value: T,
    origin: ObservationOrigin,
}

impl<T> fmt::Debug for ObservedValue<T> {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ObservedValue")
            .field("origin", &self.origin)
            .finish_non_exhaustive()
    }
}

impl<T> ObservedValue<T> {
    /// Creates an observed value with explicit provenance.
    #[must_use]
    pub const fn new(value: T, origin: ObservationOrigin) -> Self {
        Self { value, origin }
    }

    /// Returns the value exactly as observed.
    #[must_use]
    pub const fn value(&self) -> &T {
        &self.value
    }

    /// Returns the source disposition of the value.
    #[must_use]
    pub const fn origin(&self) -> ObservationOrigin {
        self.origin
    }
}

/// Stable semantic identifier for bounded metadata not modelled by this release.
///
/// The identifier is intentionally independent from a JSON spelling.  The accompanying
/// [`UnmodelledField`] records its observed JSON path and kind, but never the raw value.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum UnmodelledFieldId {
    /// Container `HostConfig` data outside the bounded typed subset.
    ContainerHostConfig,
    /// Container secret-grant metadata outside the bounded typed subset.
    ContainerSecretGrant,
    /// Container configuration data outside the bounded typed subset.
    ContainerConfig,
    /// Container network-settings data outside the bounded typed subset.
    ContainerNetworkSettings,
    /// Container mount data outside the bounded typed subset.
    ContainerMount,
    /// Other container inspect data outside the bounded typed subset.
    ContainerTopLevel,
    /// Pod membership data outside the bounded typed subset.
    PodMember,
    /// Pod infra-configuration data outside the bounded typed subset.
    PodInfraConfig,
    /// Other pod inspect data outside the bounded typed subset.
    PodTopLevel,
    /// Network subnet data outside the bounded typed subset.
    NetworkSubnet,
    /// Network route data outside the bounded typed subset.
    NetworkRoute,
    /// Other network inspect data outside the bounded typed subset.
    NetworkTopLevel,
    /// Volume inspect data outside the bounded typed subset.
    VolumeTopLevel,
    /// Image configuration data outside the bounded typed subset.
    ImageConfig,
    /// Other image inspect data outside the bounded typed subset.
    ImageTopLevel,
    /// Secret specification metadata outside the bounded typed subset.
    SecretSpec,
    /// Other secret inspect data outside the bounded typed subset.
    SecretTopLevel,
}

impl UnmodelledFieldId {
    /// Returns the stable semantic identifier.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::ContainerHostConfig => "podman.native.container.host-config",
            Self::ContainerSecretGrant => "podman.native.container.secret-grant",
            Self::ContainerConfig => "podman.native.container.config",
            Self::ContainerNetworkSettings => "podman.native.container.network-settings",
            Self::ContainerMount => "podman.native.container.mount",
            Self::ContainerTopLevel => "podman.native.container.top-level",
            Self::PodMember => "podman.native.pod.member",
            Self::PodInfraConfig => "podman.native.pod.infra-config",
            Self::PodTopLevel => "podman.native.pod.top-level",
            Self::NetworkSubnet => "podman.native.network.subnet",
            Self::NetworkRoute => "podman.native.network.route",
            Self::NetworkTopLevel => "podman.native.network.top-level",
            Self::VolumeTopLevel => "podman.native.volume.top-level",
            Self::ImageConfig => "podman.native.image.config",
            Self::ImageTopLevel => "podman.native.image.top-level",
            Self::SecretSpec => "podman.native.secret.spec",
            Self::SecretTopLevel => "podman.native.secret.top-level",
        }
    }
}

/// Bounded, redacted metadata for one native field that remains unmodelled.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UnmodelledField {
    id: UnmodelledFieldId,
    path: String,
    json_kind: JsonValueKind,
    resource: ResourceIdentity,
    evidence: ResourceEvidence,
}

impl UnmodelledField {
    #[allow(clippy::too_many_arguments)] // private typed decoder construction keeps every field explicit.
    pub(crate) fn new(
        path: String,
        json_kind: JsonValueKind,
        resource: ResourceIdentity,
        evidence: ResourceEvidence,
    ) -> Self {
        Self {
            id: semantic_unmodelled_id(resource.kind(), &path),
            path,
            json_kind,
            resource,
            evidence,
        }
    }

    /// Returns the stable semantic ID, never a raw native value.
    #[must_use]
    pub fn id(&self) -> &UnmodelledFieldId {
        &self.id
    }

    /// Returns the observed JSON path.
    #[must_use]
    pub fn path(&self) -> &str {
        &self.path
    }

    /// Returns the observed JSON value kind.
    #[must_use]
    pub const fn json_kind(&self) -> JsonValueKind {
        self.json_kind
    }

    /// Returns the carrying resource identity.
    #[must_use]
    pub fn resource(&self) -> &ResourceIdentity {
        &self.resource
    }

    /// Returns immutable version evidence for this observation.
    #[must_use]
    pub fn evidence(&self) -> &ResourceEvidence {
        &self.evidence
    }
}

fn semantic_unmodelled_id(kind: ResourceKind, path: &str) -> UnmodelledFieldId {
    match (kind, path) {
        (ResourceKind::Container, value) if value.starts_with("$.HostConfig") => UnmodelledFieldId::ContainerHostConfig,
        (ResourceKind::Container, value) if value.starts_with("$.Config.Secrets") => {
            UnmodelledFieldId::ContainerSecretGrant
        }
        (ResourceKind::Container, value) if value.starts_with("$.Config") => UnmodelledFieldId::ContainerConfig,
        (ResourceKind::Container, value) if value.starts_with("$.NetworkSettings") => {
            UnmodelledFieldId::ContainerNetworkSettings
        }
        (ResourceKind::Container, value) if value.starts_with("$.Mounts") => UnmodelledFieldId::ContainerMount,
        (ResourceKind::Pod, value) if value.starts_with("$.Containers") => UnmodelledFieldId::PodMember,
        (ResourceKind::Pod, value) if value.starts_with("$.InfraConfig") => UnmodelledFieldId::PodInfraConfig,
        (ResourceKind::Network, value) if value.starts_with("$.subnets") => UnmodelledFieldId::NetworkSubnet,
        (ResourceKind::Network, value) if value.starts_with("$.routes") => UnmodelledFieldId::NetworkRoute,
        (ResourceKind::Image, value) if value.starts_with("$.Config") => UnmodelledFieldId::ImageConfig,
        (ResourceKind::Secret, value) if value.starts_with("$.Spec") => UnmodelledFieldId::SecretSpec,
        (ResourceKind::Container, _) => UnmodelledFieldId::ContainerTopLevel,
        (ResourceKind::Pod, _) => UnmodelledFieldId::PodTopLevel,
        (ResourceKind::Network, _) => UnmodelledFieldId::NetworkTopLevel,
        (ResourceKind::Volume, _) => UnmodelledFieldId::VolumeTopLevel,
        (ResourceKind::Image, _) => UnmodelledFieldId::ImageTopLevel,
        (ResourceKind::Secret, _) => UnmodelledFieldId::SecretTopLevel,
    }
}

/// Completeness state for bounded unmodelled metadata.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum UnmodelledCompleteness {
    /// All direct unmodelled fields were retained within configured bounds.
    Complete,
    /// The observation is partial or the retention budget overflowed.
    Incomplete,
}

/// Acquisition state of one resource observation.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ResourceObservationState {
    /// The inspected response decoded according to the current native contract.
    Complete,
    /// The resource could not be acquired during the non-atomic inventory read.
    Unavailable,
    /// The resource inspect response was malformed or contradicted the list identity.
    Malformed,
}

/// Resource-wide observation information shared by every detail variant.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ObservationHeader {
    identity: ResourceIdentity,
    state: ResourceObservationState,
    evidence: ResourceEvidence,
    findings: Vec<InventoryFinding>,
    unmodelled: Vec<UnmodelledField>,
    unmodelled_completeness: UnmodelledCompleteness,
}

impl ObservationHeader {
    pub(crate) fn complete(
        identity: ResourceIdentity,
        evidence: ResourceEvidence,
        findings: Vec<InventoryFinding>,
        unmodelled: Vec<UnmodelledField>,
        unmodelled_completeness: UnmodelledCompleteness,
    ) -> Self {
        Self {
            identity,
            state: ResourceObservationState::Complete,
            evidence,
            findings,
            unmodelled,
            unmodelled_completeness,
        }
    }

    pub(crate) fn incomplete(
        identity: ResourceIdentity,
        evidence: ResourceEvidence,
        state: ResourceObservationState,
        findings: Vec<InventoryFinding>,
    ) -> Self {
        Self {
            identity,
            state,
            evidence,
            findings,
            unmodelled: Vec::new(),
            unmodelled_completeness: UnmodelledCompleteness::Incomplete,
        }
    }

    /// Returns the stable native identity.
    #[must_use]
    pub fn identity(&self) -> &ResourceIdentity {
        &self.identity
    }

    /// Returns the typed non-atomic acquisition state for this resource.
    #[must_use]
    pub const fn state(&self) -> ResourceObservationState {
        self.state
    }

    /// Returns immutable source/version evidence.
    #[must_use]
    pub fn evidence(&self) -> &ResourceEvidence {
        &self.evidence
    }

    /// Returns redacted structured findings for this resource.
    #[must_use]
    pub fn findings(&self) -> &[InventoryFinding] {
        &self.findings
    }

    pub(crate) fn findings_mut(&mut self) -> &mut Vec<InventoryFinding> {
        &mut self.findings
    }

    /// Returns bounded unmodelled metadata without raw values.
    #[must_use]
    pub fn unmodelled_fields(&self) -> &[UnmodelledField] {
        &self.unmodelled
    }

    /// Returns whether bounded metadata accounts for all unmodelled fields.
    #[must_use]
    pub const fn unmodelled_completeness(&self) -> UnmodelledCompleteness {
        self.unmodelled_completeness
    }
}

/// A relationship used internally by canonical discovery derivation.
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) struct NativeRelationship {
    pub(crate) kind: ResourceKind,
    /// One relationship can retain several native references when the wire format carries an
    /// identifier and a name for the same grant.  Resolution requires every supplied reference
    /// to select the same target; discovery must never choose one spelling silently.
    pub(crate) references: Vec<String>,
    /// Every source location that asserted this one native relationship.
    pub(crate) field_paths: Vec<String>,
}

impl NativeRelationship {
    pub(crate) fn new(kind: ResourceKind, target_id: impl Into<String>, field_path: impl Into<String>) -> Self {
        Self {
            kind,
            references: vec![target_id.into()],
            field_paths: vec![field_path.into()],
        }
    }

    pub(crate) fn coalesced(
        kind: ResourceKind,
        references: impl IntoIterator<Item = (String, String)>,
    ) -> Option<Self> {
        let mut values = Vec::new();
        let mut paths = Vec::new();
        for (value, path) in references {
            if !values.contains(&value) {
                values.push(value);
            }
            paths.push(path);
        }
        (!values.is_empty()).then_some(Self {
            kind,
            references: values,
            field_paths: paths,
        })
    }
}

/// A protected runtime environment observation.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProtectedEnvironment {
    entries: Vec<ProtectedEnvironmentEntry>,
}

impl ProtectedEnvironment {
    pub(crate) fn new(entries: Vec<ProtectedEnvironmentEntry>) -> Self {
        Self { entries }
    }

    /// Returns variable names and protected value states in source order.
    #[must_use]
    pub fn entries(&self) -> &[ProtectedEnvironmentEntry] {
        &self.entries
    }
}

/// One protected runtime environment name/value-state pair.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProtectedEnvironmentEntry {
    name: String,
    value: ProtectedEnvironmentValue,
}

impl ProtectedEnvironmentEntry {
    pub(crate) fn new(name: String, value: ProtectedEnvironmentValue) -> Self {
        Self { name, value }
    }

    /// Returns the variable name.
    #[must_use]
    pub fn name(&self) -> &str {
        &self.name
    }

    /// Returns the protected state, never a public deployment value.
    #[must_use]
    pub fn value(&self) -> &ProtectedEnvironmentValue {
        &self.value
    }
}

/// Protected runtime environment value state.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ProtectedEnvironmentValue {
    /// The source value is deliberately not retained.
    Redacted,
    /// An explicitly authorized opaque value; formatting and snapshots remain redacted.
    AuthorizedOpaque(SensitiveEnvironmentValue),
}

/// A bounded configured label collection.
pub type Labels = BTreeMap<String, String>;

/// A configured container command observed from `Config.Cmd`.
///
/// This is native input evidence, not a deployment argument type. Its constructor stays private
/// so callers cannot accidentally manufacture an observation with invented provenance.
#[derive(Clone, Eq, PartialEq)]
pub struct ConfiguredContainerCommand(Vec<String>);

impl ConfiguredContainerCommand {
    pub(crate) const fn new(arguments: Vec<String>) -> Self {
        Self(arguments)
    }

    /// Returns the declared command arguments in their native order.
    #[must_use]
    pub fn arguments(&self) -> &[String] {
        &self.0
    }
}

impl fmt::Debug for ConfiguredContainerCommand {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ConfiguredContainerCommand")
            .field("argument_count", &self.0.len())
            .finish()
    }
}

/// A configured container entrypoint observed from `Config.Entrypoint`.
#[derive(Clone, Eq, PartialEq)]
pub struct ConfiguredContainerEntrypoint(Vec<String>);

impl ConfiguredContainerEntrypoint {
    pub(crate) const fn new(arguments: Vec<String>) -> Self {
        Self(arguments)
    }

    /// Returns the declared entrypoint arguments in their native order.
    #[must_use]
    pub fn arguments(&self) -> &[String] {
        &self.0
    }
}

impl fmt::Debug for ConfiguredContainerEntrypoint {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ConfiguredContainerEntrypoint")
            .field("argument_count", &self.0.len())
            .finish()
    }
}

macro_rules! configured_container_text {
    ($type:ident, $doc:literal) => {
        #[doc = $doc]
        #[derive(Clone, Eq, PartialEq)]
        pub struct $type(String);

        impl $type {
            pub(crate) fn new(value: String) -> Self {
                Self(value)
            }

            /// Returns the native configured spelling.
            #[must_use]
            pub fn value(&self) -> &str {
                &self.0
            }
        }

        impl fmt::Debug for $type {
            fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                formatter.write_str(concat!(stringify!($type), "([redacted])"))
            }
        }
    };
}

configured_container_text!(
    ConfiguredContainerUser,
    "A configured container user from `Config.User`."
);
configured_container_text!(
    ConfiguredContainerWorkdir,
    "A configured container working directory from `Config.WorkingDir`."
);
configured_container_text!(
    ConfiguredContainerHostname,
    "A configured container hostname from `Config.Hostname`."
);

/// One native relationship reference with its exact source location.
#[derive(Clone, Eq, PartialEq)]
pub struct NativeResourceReference {
    reference: String,
    field_path: String,
}

impl NativeResourceReference {
    pub(crate) fn new(reference: String, field_path: String) -> Self {
        Self { reference, field_path }
    }

    /// Returns the native identifier or name that requires explicit resolution.
    #[must_use]
    pub fn reference(&self) -> &str {
        &self.reference
    }

    /// Returns the reviewed native field that supplied this reference.
    #[must_use]
    pub fn field_path(&self) -> &str {
        &self.field_path
    }
}

impl fmt::Debug for NativeResourceReference {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("NativeResourceReference")
            .field("field_path", &self.field_path)
            .finish_non_exhaustive()
    }
}

/// A typed declared container mount kind.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ContainerMountKind {
    /// A named Podman volume.
    NamedVolume,
    /// A host bind mount. Its source path stays local-resolution evidence.
    Bind,
}

/// The source of a typed native mount.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
pub enum ContainerMountSource {
    /// A configured named-volume reference.
    NamedVolume(String),
    /// A host-specific path observed from the local Podman service.
    LocalBindPath(String),
}

/// An explicitly configured `SELinux` relabel policy for one bind mount.
///
/// Podman reports this intent as the case-sensitive `z` or `Z` option. The
/// decoder retains only that closed semantic choice; it never exposes the
/// surrounding native bind specification.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ContainerMountSelinuxRelabel {
    /// Relabel content so multiple containers may share it (`z`).
    Shared,
    /// Relabel content for private use by one container (`Z`).
    Private,
}

/// A privacy-safe consistency result for the image operand in Podman's recorded
/// creation command.
///
/// The native spelling is compared transiently and is never retained. This is
/// creation evidence only: it neither proves an image was pulled nor records a
/// build or other image history.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum AuthoredImageSpellingHint {
    /// The transient operand matched the configured `ImageName` spelling.
    MatchesConfiguredImage,
    /// The transient operand matched the local resolved image identifier.
    MatchesLocalImageId,
    /// Both typed image observations were available, and the operand matched
    /// neither the configured spelling nor the local resolved identifier.
    Contradictory,
}

/// A privacy-safe SELinux-relabel result from Podman's recorded creation command.
///
/// The index identifies a typed inspect mount. It does not expose a native
/// command argument, host path, mount source, or mount destination.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum AuthoredMountRelabelHint {
    /// A command `z` choice agreed with the indexed typed mount.
    Shared {
        /// Index of the correlated typed inspect mount.
        mount_index: usize,
    },
    /// A command `Z` choice agreed with the indexed typed mount.
    Private {
        /// Index of the correlated typed inspect mount.
        mount_index: usize,
    },
    /// A command relabel choice could not be reconciled with the typed mount.
    Contradictory {
        /// Index of the correlated typed inspect mount.
        mount_index: usize,
    },
}

/// Bounded, redacted evidence derived transiently from `CreateCommand`.
///
/// No raw command component is retained. In particular, environment values,
/// secrets, paths, image spellings, and post-image command payloads cannot be
/// recovered from this value.
/// Image-spelling and mount-relabel projections retain independent
/// [`ObservationField`] states.
#[derive(Clone, Eq, PartialEq)]
pub struct ContainerCreationEvidence {
    image: ObservationField<AuthoredImageSpellingHint>,
    mount_relabels: ObservationField<Vec<AuthoredMountRelabelHint>>,
}

impl ContainerCreationEvidence {
    pub(crate) fn new(
        image: ObservationField<AuthoredImageSpellingHint>,
        mount_relabels: ObservationField<Vec<AuthoredMountRelabelHint>>,
    ) -> Self {
        Self { image, mount_relabels }
    }

    /// Returns the closed image-spelling consistency result or its independent
    /// observation state.
    #[must_use]
    pub const fn image(&self) -> &ObservationField<AuthoredImageSpellingHint> {
        &self.image
    }

    /// Returns closed relabel consistency results by typed inspect-mount index,
    /// or their independent observation state.
    #[must_use]
    pub const fn mount_relabels(&self) -> &ObservationField<Vec<AuthoredMountRelabelHint>> {
        &self.mount_relabels
    }
}

impl fmt::Debug for ContainerCreationEvidence {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ContainerCreationEvidence")
            .field("image", &self.image)
            .field("mount_relabels", &self.mount_relabels)
            .finish()
    }
}

impl ContainerMountSource {
    /// Returns the native source spelling. A bind path is local-resolution evidence and must not
    /// be promoted automatically into portable intent.
    #[must_use]
    pub fn value(&self) -> &str {
        match self {
            Self::NamedVolume(value) | Self::LocalBindPath(value) => value,
        }
    }
}

impl fmt::Debug for ContainerMountSource {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        let kind = match self {
            Self::NamedVolume(_) => "named_volume",
            Self::LocalBindPath(_) => "local_bind_path",
        };
        formatter.debug_tuple("ContainerMountSource").field(&kind).finish()
    }
}

/// One typed native mount. Every nested field keeps its independent native observation state.
#[derive(Clone, Eq, PartialEq)]
pub struct ContainerMountObservation {
    kind: ContainerMountKind,
    source: ObservationField<ContainerMountSource>,
    local_backing_path: ObservationField<String>,
    destination: ObservationField<String>,
    writable: ObservationField<bool>,
    options: ObservationField<Vec<String>>,
    selinux_relabel: ObservationField<ContainerMountSelinuxRelabel>,
    propagation: ObservationField<String>,
    subpath: ObservationField<String>,
}

impl ContainerMountObservation {
    #[allow(clippy::too_many_arguments)]
    pub(crate) const fn new(
        kind: ContainerMountKind,
        source: ObservationField<ContainerMountSource>,
        local_backing_path: ObservationField<String>,
        destination: ObservationField<String>,
        writable: ObservationField<bool>,
        options: ObservationField<Vec<String>>,
        selinux_relabel: ObservationField<ContainerMountSelinuxRelabel>,
        propagation: ObservationField<String>,
        subpath: ObservationField<String>,
    ) -> Self {
        Self {
            kind,
            source,
            local_backing_path,
            destination,
            writable,
            options,
            selinux_relabel,
            propagation,
            subpath,
        }
    }

    /// Returns the accepted native mount kind.
    #[must_use]
    pub const fn kind(&self) -> ContainerMountKind {
        self.kind
    }
    /// Returns source evidence; bind paths are always local-resolution evidence.
    #[must_use]
    pub fn source(&self) -> &ObservationField<ContainerMountSource> {
        &self.source
    }
    /// Returns the host-specific backing path when Podman supplied one. This is always local
    /// resolution evidence and cannot be promoted automatically.
    #[must_use]
    pub fn local_backing_path(&self) -> &ObservationField<String> {
        &self.local_backing_path
    }
    /// Returns the configured container destination.
    #[must_use]
    pub fn destination(&self) -> &ObservationField<String> {
        &self.destination
    }
    /// Returns the observed writable setting.
    #[must_use]
    pub fn writable(&self) -> &ObservationField<bool> {
        &self.writable
    }
    /// Returns mount options when the native response supplied them.
    #[must_use]
    pub fn options(&self) -> &ObservationField<Vec<String>> {
        &self.options
    }

    /// Returns the configured `SELinux` relabel choice recovered from bounded
    /// native mount evidence.
    #[must_use]
    pub fn selinux_relabel(&self) -> &ObservationField<ContainerMountSelinuxRelabel> {
        &self.selinux_relabel
    }
    /// Returns mount propagation when the native response supplied it.
    #[must_use]
    pub fn propagation(&self) -> &ObservationField<String> {
        &self.propagation
    }
    /// Returns named-volume subpath evidence when the native response supplied it.
    #[must_use]
    pub fn subpath(&self) -> &ObservationField<String> {
        &self.subpath
    }
}

impl fmt::Debug for ContainerMountObservation {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ContainerMountObservation")
            .field("kind", &self.kind)
            .field("source", &self.source)
            .field(
                "local_backing_path_state",
                &observation_field_state(&self.local_backing_path),
            )
            .field("destination_state", &observation_field_state(&self.destination))
            .field("writable", &self.writable)
            .field(
                "option_count",
                &self.options.observed().map_or(0, |options| options.value().len()),
            )
            .field("selinux_relabel", &self.selinux_relabel)
            .field("propagation_state", &observation_field_state(&self.propagation))
            .field("subpath_state", &observation_field_state(&self.subpath))
            .finish()
    }
}

fn observation_field_state<T>(field: &ObservationField<T>) -> &'static str {
    match field {
        ObservationField::Observed(_) => "observed",
        ObservationField::Absent => "absent",
        ObservationField::Unavailable => "unavailable",
        ObservationField::Malformed => "malformed",
        ObservationField::VersionInapplicable => "version-inapplicable",
        ObservationField::NotApplicable => "not-applicable",
        ObservationField::Unmodelled(_) => "unmodelled",
    }
}

/// Coalesced secret ID/name evidence. Both spellings must resolve to one secret before traversal.
#[derive(Clone, Eq, PartialEq)]
pub struct ContainerSecretReference {
    id: Option<NativeResourceReference>,
    name: Option<NativeResourceReference>,
}

impl ContainerSecretReference {
    pub(crate) const fn new(id: Option<NativeResourceReference>, name: Option<NativeResourceReference>) -> Self {
        Self { id, name }
    }
    /// Returns the optional native secret-ID source evidence.
    #[must_use]
    pub fn id(&self) -> Option<&NativeResourceReference> {
        self.id.as_ref()
    }
    /// Returns the optional native secret-name source evidence.
    #[must_use]
    pub fn name(&self) -> Option<&NativeResourceReference> {
        self.name.as_ref()
    }
}

impl fmt::Debug for ContainerSecretReference {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ContainerSecretReference")
            .field("has_id", &self.id.is_some())
            .field("has_name", &self.name.is_some())
            .finish()
    }
}

/// One typed native secret grant. It never carries secret payload bytes.
#[derive(Clone, Eq, PartialEq)]
pub struct ContainerSecretGrantObservation {
    reference: ObservationField<ContainerSecretReference>,
    uid: ObservationField<u32>,
    gid: ObservationField<u32>,
    mode: ObservationField<u32>,
}

impl ContainerSecretGrantObservation {
    pub(crate) const fn new(
        reference: ObservationField<ContainerSecretReference>,
        uid: ObservationField<u32>,
        gid: ObservationField<u32>,
        mode: ObservationField<u32>,
    ) -> Self {
        Self {
            reference,
            uid,
            gid,
            mode,
        }
    }
    /// Returns coalesced ID/name source evidence.
    #[must_use]
    pub fn reference(&self) -> &ObservationField<ContainerSecretReference> {
        &self.reference
    }
    /// Returns effective UID metadata. Podman inspect does not preserve whether zero was explicit.
    #[must_use]
    pub fn uid(&self) -> &ObservationField<u32> {
        &self.uid
    }
    /// Returns effective GID metadata. Podman inspect does not preserve whether zero was explicit.
    #[must_use]
    pub fn gid(&self) -> &ObservationField<u32> {
        &self.gid
    }
    /// Returns effective file-mode metadata. Podman inspect does not preserve whether zero was explicit.
    #[must_use]
    pub fn mode(&self) -> &ObservationField<u32> {
        &self.mode
    }
}

impl fmt::Debug for ContainerSecretGrantObservation {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ContainerSecretGrantObservation")
            .field("reference", &self.reference)
            .field("uid", &self.uid)
            .field("gid", &self.gid)
            .field("mode", &self.mode)
            .finish()
    }
}

/// A bounded native restart policy name observed from HostConfig.RestartPolicy.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum NativeRestartPolicyName {
    /// Never restart automatically.
    No,
    /// Always restart automatically.
    Always,
    /// Restart after a failure.
    OnFailure,
    /// Restart unless explicitly stopped.
    UnlessStopped,
}

/// Typed, effective native restart-policy evidence.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeRestartPolicyObservation {
    name: ObservationField<NativeRestartPolicyName>,
    maximum_retry_count: ObservationField<u64>,
}

impl NativeRestartPolicyObservation {
    pub(crate) const fn new(
        name: ObservationField<NativeRestartPolicyName>,
        maximum_retry_count: ObservationField<u64>,
    ) -> Self {
        Self {
            name,
            maximum_retry_count,
        }
    }

    /// Returns the effective policy name or its field state.
    #[must_use]
    pub fn name(&self) -> &ObservationField<NativeRestartPolicyName> {
        &self.name
    }

    /// Returns the effective native retry count, including valid zero.
    #[must_use]
    pub fn maximum_retry_count(&self) -> &ObservationField<u64> {
        &self.maximum_retry_count
    }
}

/// A protected health-check command. Its argument values are never formatted or snapshotted.
#[derive(Clone, Eq, PartialEq)]
pub struct ProtectedHealthCommand {
    arguments: Vec<String>,
}

impl ProtectedHealthCommand {
    pub(crate) const fn new(arguments: Vec<String>) -> Self {
        Self { arguments }
    }

    /// Returns the number of protected command arguments without disclosing their values.
    #[must_use]
    pub fn argument_count(&self) -> usize {
        self.arguments.len()
    }
    /// Lets an explicitly authorized caller use arguments without formatting or serializing them.
    pub fn expose<R>(&self, use_arguments: impl FnOnce(&[String]) -> R) -> R {
        use_arguments(&self.arguments)
    }
}

impl fmt::Debug for ProtectedHealthCommand {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ProtectedHealthCommand")
            .field("argument_count", &self.arguments.len())
            .finish()
    }
}

impl fmt::Display for ProtectedHealthCommand {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter.write_str("[redacted]")
    }
}

/// Native health command syntax with values retained as protected evidence.
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum NativeHealthCommand {
    /// Podman's explicit NONE health-check form.
    Disabled,
    /// A shell command whose arguments are protected.
    Shell(ProtectedHealthCommand),
    /// A direct executable command whose arguments are protected.
    Exec(ProtectedHealthCommand),
}

/// Typed normal-health observation from Config.Healthcheck.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeHealthCheckObservation {
    command: ObservationField<NativeHealthCommand>,
    interval: ObservationField<i64>,
    timeout: ObservationField<i64>,
    retries: ObservationField<u64>,
    start_period: ObservationField<i64>,
}

impl NativeHealthCheckObservation {
    pub(crate) const fn new(
        command: ObservationField<NativeHealthCommand>,
        interval: ObservationField<i64>,
        timeout: ObservationField<i64>,
        retries: ObservationField<u64>,
        start_period: ObservationField<i64>,
    ) -> Self {
        Self {
            command,
            interval,
            timeout,
            retries,
            start_period,
        }
    }

    /// Returns protected health-command evidence or its field state.
    #[must_use]
    pub fn command(&self) -> &ObservationField<NativeHealthCommand> {
        &self.command
    }
    /// Returns the native interval, including effective zero.
    #[must_use]
    pub fn interval(&self) -> &ObservationField<i64> {
        &self.interval
    }
    /// Returns the native timeout, including effective zero.
    #[must_use]
    pub fn timeout(&self) -> &ObservationField<i64> {
        &self.timeout
    }
    /// Returns the effective native retry count, including zero.
    #[must_use]
    pub fn retries(&self) -> &ObservationField<u64> {
        &self.retries
    }
    /// Returns the native start period, including effective zero.
    #[must_use]
    pub fn start_period(&self) -> &ObservationField<i64> {
        &self.start_period
    }
}

/// The bounded normal-health failure action reported by Podman.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum NativeHealthFailureAction {
    /// Retains the unhealthy state without stopping the container.
    None,
    /// Kills the container.
    Kill,
    /// Restarts the container.
    Restart,
    /// Stops the container.
    Stop,
}

/// Typed startup-health observation from Config.StartupHealthCheck.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeStartupHealthCheckObservation {
    command: ObservationField<NativeHealthCommand>,
    interval: ObservationField<i64>,
    timeout: ObservationField<i64>,
    retries: ObservationField<u64>,
    start_period: ObservationField<i64>,
    successes: ObservationField<u64>,
}

impl NativeStartupHealthCheckObservation {
    pub(crate) const fn new(
        command: ObservationField<NativeHealthCommand>,
        interval: ObservationField<i64>,
        timeout: ObservationField<i64>,
        retries: ObservationField<u64>,
        start_period: ObservationField<i64>,
        successes: ObservationField<u64>,
    ) -> Self {
        Self {
            command,
            interval,
            timeout,
            retries,
            start_period,
            successes,
        }
    }

    /// Returns protected startup-command evidence or its field state.
    #[must_use]
    pub fn command(&self) -> &ObservationField<NativeHealthCommand> {
        &self.command
    }
    /// Returns the native interval, including effective zero.
    #[must_use]
    pub fn interval(&self) -> &ObservationField<i64> {
        &self.interval
    }
    /// Returns the native timeout, including effective zero.
    #[must_use]
    pub fn timeout(&self) -> &ObservationField<i64> {
        &self.timeout
    }
    /// Returns the effective native retry count, including zero.
    #[must_use]
    pub fn retries(&self) -> &ObservationField<u64> {
        &self.retries
    }
    /// Returns the effective native start period, including zero.
    #[must_use]
    pub fn start_period(&self) -> &ObservationField<i64> {
        &self.start_period
    }
    /// Returns the effective native startup success threshold, including zero.
    #[must_use]
    pub fn successes(&self) -> &ObservationField<u64> {
        &self.successes
    }
}

/// The bounded logging drivers represented by this native observation batch.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum NativeLogDriver {
    /// Podman's journald driver.
    Journald,
    /// Podman's k8s-file driver.
    K8sFile,
}

/// Native logging observation from HostConfig.LogConfig.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeLoggingObservation {
    driver: ObservationField<NativeLogDriver>,
    size: ObservationField<String>,
}

impl NativeLoggingObservation {
    pub(crate) const fn new(driver: ObservationField<NativeLogDriver>, size: ObservationField<String>) -> Self {
        Self { driver, size }
    }

    /// Returns the effective logging driver or its field state.
    #[must_use]
    pub fn driver(&self) -> &ObservationField<NativeLogDriver> {
        &self.driver
    }

    /// Returns the effective native log-size spelling or its field state.
    #[must_use]
    pub fn size(&self) -> &ObservationField<String> {
        &self.size
    }
}

/// One reviewed Linux capability spelling from native container inspection.
///
/// This input-only type is deliberately separate from the deployment capability type.
/// Native order and duplicates are evidence and therefore remain intact.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeCapability(String);

impl NativeCapability {
    pub(crate) fn new(value: String) -> Self {
        Self(value)
    }

    /// Returns the exact reviewed native capability spelling.
    #[must_use]
    pub fn as_str(&self) -> &str {
        &self.0
    }
}

/// Opaque native security options. Values are deliberately never retained or exposed.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeOpaqueSecurityOptions {
    count: usize,
}

impl NativeOpaqueSecurityOptions {
    pub(crate) const fn new(count: usize) -> Self {
        Self { count }
    }

    /// Returns the number of opaque security options.
    #[must_use]
    pub const fn len(&self) -> usize {
        self.count
    }

    /// Returns whether no opaque security options were observed.
    #[must_use]
    pub const fn is_empty(&self) -> bool {
        self.count == 0
    }
}

/// Effective native security evidence from `HostConfig`.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeSecurityObservation {
    privileged: ObservationField<bool>,
    cap_add: ObservationField<Vec<NativeCapability>>,
    cap_drop: ObservationField<Vec<NativeCapability>>,
    security_options: ObservationField<NativeOpaqueSecurityOptions>,
    read_only_root_filesystem: ObservationField<bool>,
}

impl NativeSecurityObservation {
    pub(crate) const fn new(
        privileged: ObservationField<bool>,
        cap_add: ObservationField<Vec<NativeCapability>>,
        cap_drop: ObservationField<Vec<NativeCapability>>,
        security_options: ObservationField<NativeOpaqueSecurityOptions>,
        read_only_root_filesystem: ObservationField<bool>,
    ) -> Self {
        Self {
            privileged,
            cap_add,
            cap_drop,
            security_options,
            read_only_root_filesystem,
        }
    }

    /// Returns effective privileged state.
    #[must_use]
    pub fn privileged(&self) -> &ObservationField<bool> {
        &self.privileged
    }

    /// Returns added capabilities in native order, including duplicates.
    #[must_use]
    pub fn cap_add(&self) -> &ObservationField<Vec<NativeCapability>> {
        &self.cap_add
    }

    /// Returns dropped capabilities in native order, including duplicates.
    #[must_use]
    pub fn cap_drop(&self) -> &ObservationField<Vec<NativeCapability>> {
        &self.cap_drop
    }

    /// Returns only the count and state of opaque security options.
    #[must_use]
    pub fn security_options(&self) -> &ObservationField<NativeOpaqueSecurityOptions> {
        &self.security_options
    }

    /// Returns effective read-only-root-filesystem state.
    #[must_use]
    pub fn read_only_root_filesystem(&self) -> &ObservationField<bool> {
        &self.read_only_root_filesystem
    }
}

/// A bounded native private or host namespace mode.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum NativeNamespaceMode {
    /// A private namespace.
    Private,
    /// The host namespace.
    Host,
}

/// A bounded native IPC namespace mode.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum NativeIpcNamespaceMode {
    /// A private IPC namespace.
    Private,
    /// The host IPC namespace.
    Host,
    /// A shareable private IPC namespace.
    Shareable,
    /// No IPC namespace.
    None,
}

/// Effective native namespace evidence from `HostConfig`.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeNamespaceObservation {
    pid: ObservationField<NativeNamespaceMode>,
    ipc: ObservationField<NativeIpcNamespaceMode>,
    uts: ObservationField<NativeNamespaceMode>,
    cgroup: ObservationField<NativeNamespaceMode>,
}

impl NativeNamespaceObservation {
    pub(crate) const fn new(
        pid: ObservationField<NativeNamespaceMode>,
        ipc: ObservationField<NativeIpcNamespaceMode>,
        uts: ObservationField<NativeNamespaceMode>,
        cgroup: ObservationField<NativeNamespaceMode>,
    ) -> Self {
        Self { pid, ipc, uts, cgroup }
    }

    /// Returns effective PID namespace evidence.
    #[must_use]
    pub fn pid(&self) -> &ObservationField<NativeNamespaceMode> {
        &self.pid
    }

    /// Returns effective IPC namespace evidence.
    #[must_use]
    pub fn ipc(&self) -> &ObservationField<NativeIpcNamespaceMode> {
        &self.ipc
    }

    /// Returns effective UTS namespace evidence.
    #[must_use]
    pub fn uts(&self) -> &ObservationField<NativeNamespaceMode> {
        &self.uts
    }

    /// Returns effective cgroup namespace evidence.
    #[must_use]
    pub fn cgroup(&self) -> &ObservationField<NativeNamespaceMode> {
        &self.cgroup
    }
}

/// One native ulimit observation. Values are retained exactly without output-intent validation.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeUlimitObservation {
    name: ObservationField<String>,
    soft: ObservationField<i64>,
    hard: ObservationField<i64>,
}

impl NativeUlimitObservation {
    pub(crate) const fn new(
        name: ObservationField<String>,
        soft: ObservationField<i64>,
        hard: ObservationField<i64>,
    ) -> Self {
        Self { name, soft, hard }
    }

    /// Returns the exact native limit name.
    #[must_use]
    pub fn name(&self) -> &ObservationField<String> {
        &self.name
    }

    /// Returns the native soft limit, including zero and -1.
    #[must_use]
    pub fn soft(&self) -> &ObservationField<i64> {
        &self.soft
    }

    /// Returns the native hard limit, including zero and -1.
    #[must_use]
    pub fn hard(&self) -> &ObservationField<i64> {
        &self.hard
    }
}

/// Effective native CPU, memory, PID, and ulimit evidence from `HostConfig`.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeResourceControlObservation {
    cpu_shares: ObservationField<u64>,
    cpu_period: ObservationField<u64>,
    cpu_quota: ObservationField<i64>,
    memory: ObservationField<i64>,
    pids_limit: ObservationField<i64>,
    ulimits: ObservationField<Vec<NativeUlimitObservation>>,
}

impl NativeResourceControlObservation {
    pub(crate) const fn new(
        cpu_shares: ObservationField<u64>,
        cpu_period: ObservationField<u64>,
        cpu_quota: ObservationField<i64>,
        memory: ObservationField<i64>,
        pids_limit: ObservationField<i64>,
        ulimits: ObservationField<Vec<NativeUlimitObservation>>,
    ) -> Self {
        Self {
            cpu_shares,
            cpu_period,
            cpu_quota,
            memory,
            pids_limit,
            ulimits,
        }
    }

    /// Returns native CPU shares, preserving zero.
    #[must_use]
    pub fn cpu_shares(&self) -> &ObservationField<u64> {
        &self.cpu_shares
    }

    /// Returns native CPU period, preserving zero.
    #[must_use]
    pub fn cpu_period(&self) -> &ObservationField<u64> {
        &self.cpu_period
    }

    /// Returns native CPU quota, preserving zero and negative native sentinels.
    #[must_use]
    pub fn cpu_quota(&self) -> &ObservationField<i64> {
        &self.cpu_quota
    }

    /// Returns native memory bytes, preserving zero and negative native sentinels.
    #[must_use]
    pub fn memory(&self) -> &ObservationField<i64> {
        &self.memory
    }

    /// Returns native PID limit, preserving zero and -1.
    #[must_use]
    pub fn pids_limit(&self) -> &ObservationField<i64> {
        &self.pids_limit
    }

    /// Returns native ulimits in source order.
    #[must_use]
    pub fn ulimits(&self) -> &ObservationField<Vec<NativeUlimitObservation>> {
        &self.ulimits
    }
}

/// Container-specific native observations.
#[derive(Clone, Eq, PartialEq)]
pub struct ContainerObservation {
    configured_image: ObservationField<String>,
    labels: ObservationField<Labels>,
    local_image_id: ObservationField<String>,
    relationships: ObservationField<Vec<NativeRelationship>>,
    environment: ObservationField<ProtectedEnvironment>,
    command: ObservationField<ConfiguredContainerCommand>,
    entrypoint: ObservationField<ConfiguredContainerEntrypoint>,
    user: ObservationField<ConfiguredContainerUser>,
    working_directory: ObservationField<ConfiguredContainerWorkdir>,
    hostname: ObservationField<ConfiguredContainerHostname>,
    pod_membership: ObservationField<NativeResourceReference>,
    native_dependencies: ObservationField<Vec<NativeResourceReference>>,
    mounts: ObservationField<Vec<ContainerMountObservation>>,
    secret_grants: ObservationField<Vec<ContainerSecretGrantObservation>>,
    memory_swappiness: ObservationField<u64>,
    infra: ObservationField<bool>,
    restart_policy: ObservationField<NativeRestartPolicyObservation>,
    health_check: ObservationField<NativeHealthCheckObservation>,
    health_failure_action: ObservationField<NativeHealthFailureAction>,
    startup_health_check: ObservationField<NativeStartupHealthCheckObservation>,
    logging: ObservationField<NativeLoggingObservation>,
    security: ObservationField<NativeSecurityObservation>,
    namespaces: ObservationField<NativeNamespaceObservation>,
    resource_controls: ObservationField<NativeResourceControlObservation>,
    networking: ObservationField<NativeNetworkingObservation>,
    creation_evidence: ObservationField<ContainerCreationEvidence>,
}

macro_rules! observation_debug {
    ($type:ty, $($field:ident),+ $(,)?) => {
        impl fmt::Debug for $type {
            fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
                let mut debug = formatter.debug_struct(stringify!($type));
                $(debug.field(stringify!($field), &self.$field);)+
                debug.finish()
            }
        }
    };
}

observation_debug!(
    ContainerObservation,
    labels,
    configured_image,
    local_image_id,
    relationships,
    environment,
    command,
    entrypoint,
    user,
    working_directory,
    hostname,
    pod_membership,
    native_dependencies,
    mounts,
    secret_grants,
    memory_swappiness,
    infra,
    networking,
    restart_policy,
    health_check,
    health_failure_action,
    startup_health_check,
    logging,
    security,
    namespaces,
    resource_controls,
);

impl ContainerObservation {
    #[allow(clippy::too_many_arguments)] // private typed decoder construction keeps every field explicit.
    pub(crate) fn new(
        labels: ObservationField<Labels>,
        configured_image: ObservationField<String>,
        local_image_id: ObservationField<String>,
        relationships: ObservationField<Vec<NativeRelationship>>,
        environment: ObservationField<ProtectedEnvironment>,
        command: ObservationField<ConfiguredContainerCommand>,
        entrypoint: ObservationField<ConfiguredContainerEntrypoint>,
        user: ObservationField<ConfiguredContainerUser>,
        working_directory: ObservationField<ConfiguredContainerWorkdir>,
        hostname: ObservationField<ConfiguredContainerHostname>,
        pod_membership: ObservationField<NativeResourceReference>,
        native_dependencies: ObservationField<Vec<NativeResourceReference>>,
        mounts: ObservationField<Vec<ContainerMountObservation>>,
        secret_grants: ObservationField<Vec<ContainerSecretGrantObservation>>,
        memory_swappiness: ObservationField<u64>,
        infra: ObservationField<bool>,
        restart_policy: ObservationField<NativeRestartPolicyObservation>,
        health_check: ObservationField<NativeHealthCheckObservation>,
        health_failure_action: ObservationField<NativeHealthFailureAction>,
        startup_health_check: ObservationField<NativeStartupHealthCheckObservation>,
        logging: ObservationField<NativeLoggingObservation>,
        security: ObservationField<NativeSecurityObservation>,
        namespaces: ObservationField<NativeNamespaceObservation>,
        resource_controls: ObservationField<NativeResourceControlObservation>,
        networking: ObservationField<NativeNetworkingObservation>,
        creation_evidence: ObservationField<ContainerCreationEvidence>,
    ) -> Self {
        Self {
            configured_image,
            labels,
            local_image_id,
            relationships,
            environment,
            command,
            entrypoint,
            user,
            working_directory,
            hostname,
            pod_membership,
            native_dependencies,
            mounts,
            secret_grants,
            memory_swappiness,
            infra,
            restart_policy,
            health_check,
            health_failure_action,
            startup_health_check,
            logging,
            security,
            namespaces,
            resource_controls,
            networking,
            creation_evidence,
        }
    }

    /// Returns the configured container labels or their observation state.
    #[must_use]
    pub fn labels(&self) -> &ObservationField<Labels> {
        &self.labels
    }
    /// Returns the configured image spelling or its observation state.
    ///
    /// This is the only container image observation that discovery may use as a dependency edge.
    #[must_use]
    pub fn configured_image(&self) -> &ObservationField<String> {
        &self.configured_image
    }
    /// Returns the locally resolved image identity or its observation state.
    ///
    /// A local image ID proves what this Podman service used; it is not deployment intent.
    #[must_use]
    pub fn local_image_id(&self) -> &ObservationField<String> {
        &self.local_image_id
    }
    /// Returns protected runtime environment observations or their observation state.
    #[must_use]
    pub fn environment(&self) -> &ObservationField<ProtectedEnvironment> {
        &self.environment
    }
    /// Returns the configured command or its observation state.
    #[must_use]
    pub fn command(&self) -> &ObservationField<ConfiguredContainerCommand> {
        &self.command
    }
    /// Returns the configured entrypoint or its observation state.
    #[must_use]
    pub fn entrypoint(&self) -> &ObservationField<ConfiguredContainerEntrypoint> {
        &self.entrypoint
    }
    /// Returns the configured user or its observation state.
    #[must_use]
    pub fn user(&self) -> &ObservationField<ConfiguredContainerUser> {
        &self.user
    }
    /// Returns the configured working directory or its observation state.
    #[must_use]
    pub fn working_directory(&self) -> &ObservationField<ConfiguredContainerWorkdir> {
        &self.working_directory
    }
    /// Returns the configured hostname or its observation state.
    #[must_use]
    pub fn hostname(&self) -> &ObservationField<ConfiguredContainerHostname> {
        &self.hostname
    }
    /// Returns the container's configured pod-membership evidence or its state.
    #[must_use]
    pub fn pod_membership(&self) -> &ObservationField<NativeResourceReference> {
        &self.pod_membership
    }
    /// Returns declared native container dependencies or their observation state.
    #[must_use]
    pub fn native_dependencies(&self) -> &ObservationField<Vec<NativeResourceReference>> {
        &self.native_dependencies
    }
    /// Returns accepted named-volume and bind mount observations or their state.
    #[must_use]
    pub fn mounts(&self) -> &ObservationField<Vec<ContainerMountObservation>> {
        &self.mounts
    }

    /// Returns bounded, redacted creation-command consistency evidence.
    ///
    /// This is never an accessor for Podman's raw `CreateCommand`, nor evidence
    /// of pull, build, runtime, or lifecycle history.
    #[must_use]
    pub fn creation_evidence(&self) -> &ObservationField<ContainerCreationEvidence> {
        &self.creation_evidence
    }
    /// Returns typed secret grants without secret payload material or their state.
    #[must_use]
    pub fn secret_grants(&self) -> &ObservationField<Vec<ContainerSecretGrantObservation>> {
        &self.secret_grants
    }
    /// Returns the configured memory-swappiness value or its observation state.
    #[must_use]
    pub fn memory_swappiness(&self) -> &ObservationField<u64> {
        &self.memory_swappiness
    }
    /// Returns effective restart-policy evidence or its observation state.
    #[must_use]
    pub fn restart_policy(&self) -> &ObservationField<NativeRestartPolicyObservation> {
        &self.restart_policy
    }
    /// Returns effective normal-health inspect evidence or its observation state.
    ///
    /// This may include an image default and is not authored deployment intent.
    #[must_use]
    pub fn health_check(&self) -> &ObservationField<NativeHealthCheckObservation> {
        &self.health_check
    }
    /// Returns effective normal-health failure action or its observation state.
    ///
    /// This may include an image default and is not authored deployment intent.
    #[must_use]
    pub fn health_failure_action(&self) -> &ObservationField<NativeHealthFailureAction> {
        &self.health_failure_action
    }
    /// Returns effective startup-health inspect evidence or its observation state.
    ///
    /// This may include an image default and is not authored deployment intent.
    #[must_use]
    pub fn startup_health_check(&self) -> &ObservationField<NativeStartupHealthCheckObservation> {
        &self.startup_health_check
    }
    /// Returns effective logging evidence or its observation state.
    #[must_use]
    pub fn logging(&self) -> &ObservationField<NativeLoggingObservation> {
        &self.logging
    }
    /// Returns effective security evidence or its observation state.
    #[must_use]
    pub fn security(&self) -> &ObservationField<NativeSecurityObservation> {
        &self.security
    }
    /// Returns effective namespace evidence for any inspected container, including pod members.
    #[must_use]
    pub fn namespaces(&self) -> &ObservationField<NativeNamespaceObservation> {
        &self.namespaces
    }
    /// Returns effective resource-control evidence or its observation state.
    #[must_use]
    pub fn resource_controls(&self) -> &ObservationField<NativeResourceControlObservation> {
        &self.resource_controls
    }
    /// Returns the infra-container marker or its observation state.
    #[must_use]
    pub fn infra(&self) -> &ObservationField<bool> {
        &self.infra
    }
    /// Returns bounded configured networking evidence for an unpodded container.
    ///
    /// Pod-member networking is topology-owned by its pod and is never promoted here.
    #[must_use]
    pub fn networking(&self) -> &ObservationField<NativeNetworkingObservation> {
        &self.networking
    }
    pub(crate) fn relationships(&self) -> &ObservationField<Vec<NativeRelationship>> {
        &self.relationships
    }
}

/// Pod-specific native observations.
#[derive(Clone, Eq, PartialEq)]
pub struct PodObservation {
    labels: ObservationField<Labels>,
    relationships: ObservationField<Vec<NativeRelationship>>,
    create_infra: ObservationField<bool>,
    networking: ObservationField<NativeNetworkingObservation>,
}
observation_debug!(PodObservation, labels, relationships, create_infra, networking);

impl PodObservation {
    pub(crate) fn new(
        labels: ObservationField<Labels>,
        relationships: ObservationField<Vec<NativeRelationship>>,
        create_infra: ObservationField<bool>,
        networking: ObservationField<NativeNetworkingObservation>,
    ) -> Self {
        Self {
            labels,
            relationships,
            create_infra,
            networking,
        }
    }
    /// Returns the configured pod labels or their observation state.
    #[must_use]
    pub fn labels(&self) -> &ObservationField<Labels> {
        &self.labels
    }
    /// Returns whether the pod was created with an infra container.
    #[must_use]
    pub fn create_infra(&self) -> &ObservationField<bool> {
        &self.create_infra
    }
    /// Returns networking observed only from `Pod.InspectPodData.InfraConfig`.
    #[must_use]
    pub fn networking(&self) -> &ObservationField<NativeNetworkingObservation> {
        &self.networking
    }
    pub(crate) fn relationships(&self) -> &ObservationField<Vec<NativeRelationship>> {
        &self.relationships
    }
}

/// A protocol carried by a native inspected port binding.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum NativePortProtocol {
    /// TCP.
    Tcp,
    /// UDP.
    Udp,
    /// SCTP.
    Sctp,
}

/// One bounded native port-binding observation.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativePortBindingObservation {
    container_port: u16,
    protocol: NativePortProtocol,
    host_ip: ObservationField<IpAddr>,
    host_port: ObservationField<u16>,
}

impl NativePortBindingObservation {
    pub(crate) const fn new(
        container_port: u16,
        protocol: NativePortProtocol,
        host_ip: ObservationField<IpAddr>,
        host_port: ObservationField<u16>,
    ) -> Self {
        Self {
            container_port,
            protocol,
            host_ip,
            host_port,
        }
    }
    /// Returns the container port from the binding key.
    #[must_use]
    pub const fn container_port(&self) -> u16 {
        self.container_port
    }
    /// Returns the native transport protocol.
    #[must_use]
    pub const fn protocol(&self) -> NativePortProtocol {
        self.protocol
    }
    /// Returns the optional host IP or its observation state.
    #[must_use]
    pub fn host_ip(&self) -> &ObservationField<IpAddr> {
        &self.host_ip
    }
    /// Returns the optional host port or its observation state.
    #[must_use]
    pub fn host_port(&self) -> &ObservationField<u16> {
        &self.host_port
    }
}

/// Bounded, opaque native network options. Option values are deliberately never exposed.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeOpaqueNetworkOptions {
    count: usize,
}

impl NativeOpaqueNetworkOptions {
    pub(crate) const fn new(count: usize) -> Self {
        Self { count }
    }
    /// Returns the number of opaque options without exposing keys or values.
    #[must_use]
    pub const fn len(&self) -> usize {
        self.count
    }
    /// Returns whether no opaque options were observed.
    #[must_use]
    pub const fn is_empty(&self) -> bool {
        self.count == 0
    }
}

/// Native networking evidence observed from authoritative pod infra or unpodded host config.
///
/// This is deliberately separate from declared deployment networking intent. Host entries and
/// free-form network options remain non-promotable bounded metadata.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeNetworkingObservation {
    port_bindings: ObservationField<Vec<NativePortBindingObservation>>,
    create_net_ns: ObservationField<bool>,
    host_network: ObservationField<bool>,
    dns_servers: ObservationField<Vec<IpAddr>>,
    dns_search: ObservationField<Vec<String>>,
    dns_options: ObservationField<Vec<String>>,
    host_entries: ObservationField<NativeOpaqueNetworkOptions>,
    networks: ObservationField<Vec<NativeResourceReference>>,
    network_options: ObservationField<NativeOpaqueNetworkOptions>,
    no_manage_resolv_conf: ObservationField<bool>,
    no_manage_hosts: ObservationField<bool>,
    static_ip: ObservationField<IpAddr>,
    static_mac: ObservationField<String>,
}

impl NativeNetworkingObservation {
    #[allow(clippy::too_many_arguments)] // private decoder construction keeps every source field explicit.
    pub(crate) fn new(
        port_bindings: ObservationField<Vec<NativePortBindingObservation>>,
        create_net_ns: ObservationField<bool>,
        host_network: ObservationField<bool>,
        dns_servers: ObservationField<Vec<IpAddr>>,
        dns_search: ObservationField<Vec<String>>,
        dns_options: ObservationField<Vec<String>>,
        host_entries: ObservationField<NativeOpaqueNetworkOptions>,
        networks: ObservationField<Vec<NativeResourceReference>>,
        network_options: ObservationField<NativeOpaqueNetworkOptions>,
        no_manage_resolv_conf: ObservationField<bool>,
        no_manage_hosts: ObservationField<bool>,
        static_ip: ObservationField<IpAddr>,
        static_mac: ObservationField<String>,
    ) -> Self {
        Self {
            port_bindings,
            create_net_ns,
            host_network,
            dns_servers,
            dns_search,
            dns_options,
            host_entries,
            networks,
            network_options,
            no_manage_resolv_conf,
            no_manage_hosts,
            static_ip,
            static_mac,
        }
    }
    /// Returns bounded port-binding evidence.
    #[must_use]
    pub fn port_bindings(&self) -> &ObservationField<Vec<NativePortBindingObservation>> {
        &self.port_bindings
    }
    /// Returns the configured container network-namespace creation gate.
    #[must_use]
    pub fn create_net_ns(&self) -> &ObservationField<bool> {
        &self.create_net_ns
    }
    /// Returns the effective host-network gate.
    #[must_use]
    pub fn host_network(&self) -> &ObservationField<bool> {
        &self.host_network
    }
    /// Returns copied/configured DNS server evidence.
    #[must_use]
    pub fn dns_servers(&self) -> &ObservationField<Vec<IpAddr>> {
        &self.dns_servers
    }
    /// Returns copied/configured DNS search evidence.
    #[must_use]
    pub fn dns_search(&self) -> &ObservationField<Vec<String>> {
        &self.dns_search
    }
    /// Returns copied/configured DNS option evidence.
    #[must_use]
    pub fn dns_options(&self) -> &ObservationField<Vec<String>> {
        &self.dns_options
    }
    /// Returns the state of `/etc/hosts` entry data.
    ///
    /// `PodmanLens` intentionally does not parse this free-form hosts-file syntax as aliases or
    /// expose its values. A present entry list is therefore `Unmodelled`.
    #[must_use]
    pub fn host_entries(&self) -> &ObservationField<NativeOpaqueNetworkOptions> {
        &self.host_entries
    }
    /// Returns effective native network names in native order; that order is not a contract.
    #[must_use]
    pub fn networks(&self) -> &ObservationField<Vec<NativeResourceReference>> {
        &self.networks
    }
    /// Returns opaque network-option evidence without key/value semantics.
    #[must_use]
    pub fn network_options(&self) -> &ObservationField<NativeOpaqueNetworkOptions> {
        &self.network_options
    }
    /// Returns the effective resolver-management gate.
    #[must_use]
    pub fn no_manage_resolv_conf(&self) -> &ObservationField<bool> {
        &self.no_manage_resolv_conf
    }
    /// Returns the effective hosts-file-management gate.
    #[must_use]
    pub fn no_manage_hosts(&self) -> &ObservationField<bool> {
        &self.no_manage_hosts
    }
    /// Returns static IP evidence only where the inspected field has reviewed meaning.
    #[must_use]
    pub fn static_ip(&self) -> &ObservationField<IpAddr> {
        &self.static_ip
    }
    /// Returns static MAC evidence only where the inspected field has reviewed meaning.
    #[must_use]
    pub fn static_mac(&self) -> &ObservationField<String> {
        &self.static_mac
    }
}

/// Network-specific native observations.
#[derive(Clone, Eq, PartialEq)]
pub struct NetworkObservation {
    labels: ObservationField<Labels>,
    internal: ObservationField<bool>,
    options: ObservationField<NetworkOptionKeys>,
    subnets: ObservationField<Vec<NativeNetworkSubnetObservation>>,
    routes: ObservationField<Vec<NativeNetworkRouteObservation>>,
}

impl NetworkObservation {
    pub(crate) fn new(
        labels: ObservationField<Labels>,
        internal: ObservationField<bool>,
        options: ObservationField<NetworkOptionKeys>,
        subnets: ObservationField<Vec<NativeNetworkSubnetObservation>>,
        routes: ObservationField<Vec<NativeNetworkRouteObservation>>,
    ) -> Self {
        Self {
            labels,
            internal,
            options,
            subnets,
            routes,
        }
    }
    /// Returns the configured network labels or their observation state.
    #[must_use]
    pub fn labels(&self) -> &ObservationField<Labels> {
        &self.labels
    }
    /// Returns the network-internal flag or its observation state.
    #[must_use]
    pub fn internal(&self) -> &ObservationField<bool> {
        &self.internal
    }
    /// Returns only network option keys; native option values may contain credentials and are
    /// never exposed through the public observation contract.
    #[must_use]
    pub fn options(&self) -> &ObservationField<NetworkOptionKeys> {
        &self.options
    }
    /// Returns typed effective native IPAM subnet observations or their observation state.
    #[must_use]
    pub fn subnets(&self) -> &ObservationField<Vec<NativeNetworkSubnetObservation>> {
        &self.subnets
    }
    /// Returns typed effective native static-route observations or their observation state.
    #[must_use]
    pub fn routes(&self) -> &ObservationField<Vec<NativeNetworkRouteObservation>> {
        &self.routes
    }
}
observation_debug!(NetworkObservation, labels, internal, options, subnets, routes);

/// A syntax-validated native CIDR wire spelling observed from network inspection.
///
/// This is defensive raw-wire preservation, not [`crate::NetworkCidr`] deployment intent or a
/// claim that every accepted spelling is valid for every native field and Podman version.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeNetworkCidr {
    spelling: String,
    network: IpAddr,
    prefix: u8,
}

impl NativeNetworkCidr {
    pub(crate) fn parse(spelling: String) -> Option<Self> {
        let (network, prefix) = spelling.split_once('/')?;
        let network = network.parse::<IpAddr>().ok()?;
        let prefix = prefix.parse::<u8>().ok()?;
        (prefix <= if network.is_ipv4() { 32 } else { 128 }).then_some(Self {
            spelling,
            network,
            prefix,
        })
    }

    /// Returns the exact syntax-validated native CIDR wire spelling.
    #[must_use]
    pub fn as_str(&self) -> &str {
        &self.spelling
    }

    /// Returns whether an address of the same family lies within this CIDR.
    #[must_use]
    pub(crate) fn contains(&self, address: IpAddr) -> bool {
        self.network.is_ipv4() == address.is_ipv4()
            && native_masked_address(self.network, self.prefix) == native_masked_address(address, self.prefix)
    }

    /// Returns whether an address has the same family as this CIDR.
    #[must_use]
    pub(crate) const fn has_address_family(&self, address: IpAddr) -> bool {
        self.network.is_ipv4() == address.is_ipv4()
    }
}

/// An effective native network lease range with independently optional endpoint evidence.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeNetworkLeaseRange {
    start_ip: ObservationField<IpAddr>,
    end_ip: ObservationField<IpAddr>,
}

impl NativeNetworkLeaseRange {
    pub(crate) const fn new(start_ip: ObservationField<IpAddr>, end_ip: ObservationField<IpAddr>) -> Self {
        Self { start_ip, end_ip }
    }
    /// Returns the optional inclusive lease-range start address or its observation state.
    #[must_use]
    pub const fn start_ip(&self) -> &ObservationField<IpAddr> {
        &self.start_ip
    }
    /// Returns the optional inclusive lease-range end address or its observation state.
    #[must_use]
    pub const fn end_ip(&self) -> &ObservationField<IpAddr> {
        &self.end_ip
    }
}

/// One typed native IPAM subnet observation. Every nested member keeps its own observation state.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeNetworkSubnetObservation {
    cidr: ObservationField<NativeNetworkCidr>,
    gateway: ObservationField<IpAddr>,
    lease_range: ObservationField<NativeNetworkLeaseRange>,
}

impl NativeNetworkSubnetObservation {
    pub(crate) const fn new(
        cidr: ObservationField<NativeNetworkCidr>,
        gateway: ObservationField<IpAddr>,
        lease_range: ObservationField<NativeNetworkLeaseRange>,
    ) -> Self {
        Self {
            cidr,
            gateway,
            lease_range,
        }
    }
    /// Returns the native subnet CIDR evidence.
    #[must_use]
    pub fn cidr(&self) -> &ObservationField<NativeNetworkCidr> {
        &self.cidr
    }
    /// Returns the optional effective native gateway.
    #[must_use]
    pub fn gateway(&self) -> &ObservationField<IpAddr> {
        &self.gateway
    }
    /// Returns the optional effective native lease range.
    #[must_use]
    pub fn lease_range(&self) -> &ObservationField<NativeNetworkLeaseRange> {
        &self.lease_range
    }
}

/// A route kind observed from the native network inspect response.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum NativeNetworkRouteType {
    /// A forwarding route that requires a gateway.
    Unicast,
    /// A route that drops matching traffic.
    Blackhole,
    /// A route that reports the destination as unreachable.
    Unreachable,
    /// A route that reports the destination as administratively prohibited.
    Prohibit,
}

/// One typed native static-route observation. Every nested member keeps its own observation state.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeNetworkRouteObservation {
    destination: ObservationField<NativeNetworkCidr>,
    gateway: ObservationField<IpAddr>,
    metric: ObservationField<u32>,
    route_type: ObservationField<NativeNetworkRouteType>,
}

impl NativeNetworkRouteObservation {
    pub(crate) const fn new(
        destination: ObservationField<NativeNetworkCidr>,
        gateway: ObservationField<IpAddr>,
        metric: ObservationField<u32>,
        route_type: ObservationField<NativeNetworkRouteType>,
    ) -> Self {
        Self {
            destination,
            gateway,
            metric,
            route_type,
        }
    }
    /// Returns the native destination CIDR evidence.
    #[must_use]
    pub fn destination(&self) -> &ObservationField<NativeNetworkCidr> {
        &self.destination
    }
    /// Returns the optional effective native route gateway.
    #[must_use]
    pub fn gateway(&self) -> &ObservationField<IpAddr> {
        &self.gateway
    }
    /// Returns the optional effective native route metric, preserving an explicit zero.
    #[must_use]
    pub fn metric(&self) -> &ObservationField<u32> {
        &self.metric
    }
    /// Returns the native route type. This is version-inapplicable before Podman 6.0.
    #[must_use]
    pub fn route_type(&self) -> &ObservationField<NativeNetworkRouteType> {
        &self.route_type
    }
}

fn native_masked_address(address: IpAddr, prefix: u8) -> IpAddr {
    match address {
        IpAddr::V4(address) => {
            let mask = if prefix == 0 { 0 } else { u32::MAX << (32 - prefix) };
            IpAddr::V4(std::net::Ipv4Addr::from(u32::from(address) & mask))
        }
        IpAddr::V6(address) => {
            let mask = if prefix == 0 { 0 } else { u128::MAX << (128 - prefix) };
            IpAddr::V6(std::net::Ipv6Addr::from(u128::from(address) & mask))
        }
    }
}

/// Public, value-free network option observation.
#[derive(Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct NetworkOptionKeys(BTreeSet<String>);

impl NetworkOptionKeys {
    pub(crate) fn new(keys: impl IntoIterator<Item = String>) -> Self {
        Self(keys.into_iter().collect())
    }

    /// Returns observed option keys in deterministic order, without their values.
    pub fn keys(&self) -> impl Iterator<Item = &str> {
        self.0.iter().map(String::as_str)
    }

    /// Returns the number of observed option keys.
    #[must_use]
    pub fn len(&self) -> usize {
        self.0.len()
    }

    /// Returns whether no option keys were observed.
    #[must_use]
    pub fn is_empty(&self) -> bool {
        self.0.is_empty()
    }
}

impl fmt::Debug for NetworkOptionKeys {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("NetworkOptionKeys")
            .field("count", &self.len())
            .finish()
    }
}

/// The native wire representation of a volume owner ID.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum VolumeOwnerIdWireValue {
    /// Podman's reviewed `omitempty` wire shape omitted the property, which canonically may mean
    /// the Podman default of zero.
    WireAbsentMayMeanZero,
    /// A concrete numeric value was present, including literal zero.
    Explicit(UnixId),
}

/// Bounded Unix user or group identifier from a native volume response.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct UnixId(u32);

impl UnixId {
    pub(crate) const fn new(value: u32) -> Self {
        Self(value)
    }
    /// Returns the literal value reported by Podman.
    #[must_use]
    pub const fn get(self) -> u32 {
        self.0
    }
}

/// An exact, validated RFC 3339 timestamp from a native Podman response.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeTimestamp(String);

impl NativeTimestamp {
    pub(crate) fn new(value: String) -> Self {
        Self(value)
    }

    /// Returns the exact timestamp spelling reported by Podman.
    #[must_use]
    pub fn as_str(&self) -> &str {
        &self.0
    }
}

/// Count-only evidence for secret-driver options. Option names and values are never retained.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct NativeSecretDriverOptions {
    count: usize,
}

impl NativeSecretDriverOptions {
    pub(crate) const fn new(count: usize) -> Self {
        Self { count }
    }

    /// Returns the number of opaque driver options.
    #[must_use]
    pub const fn len(&self) -> usize {
        self.count
    }

    /// Returns whether no driver options were observed.
    #[must_use]
    pub const fn is_empty(&self) -> bool {
        self.count == 0
    }
}

/// Native secret-driver metadata without option names or values.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct NativeSecretDriverObservation {
    name: ObservationField<String>,
    options: ObservationField<NativeSecretDriverOptions>,
}

impl NativeSecretDriverObservation {
    pub(crate) const fn new(
        name: ObservationField<String>,
        options: ObservationField<NativeSecretDriverOptions>,
    ) -> Self {
        Self { name, options }
    }

    /// Returns the effective driver name.
    #[must_use]
    pub fn name(&self) -> &ObservationField<String> {
        &self.name
    }

    /// Returns only the state and count of opaque driver options.
    #[must_use]
    pub fn options(&self) -> &ObservationField<NativeSecretDriverOptions> {
        &self.options
    }
}

/// Volume-specific native observations.
#[derive(Clone, Eq, PartialEq)]
pub struct VolumeObservation {
    labels: ObservationField<Labels>,
    uid: ObservationField<VolumeOwnerIdWireValue>,
    gid: ObservationField<VolumeOwnerIdWireValue>,
    driver: ObservationField<String>,
    created_at: ObservationField<NativeTimestamp>,
    anonymous: ObservationField<bool>,
}
observation_debug!(VolumeObservation, labels, uid, gid, driver, created_at, anonymous);

impl VolumeObservation {
    pub(crate) fn new(
        labels: ObservationField<Labels>,
        uid: ObservationField<VolumeOwnerIdWireValue>,
        gid: ObservationField<VolumeOwnerIdWireValue>,
        driver: ObservationField<String>,
        created_at: ObservationField<NativeTimestamp>,
        anonymous: ObservationField<bool>,
    ) -> Self {
        Self {
            labels,
            uid,
            gid,
            driver,
            created_at,
            anonymous,
        }
    }
    /// Returns the configured volume labels or their observation state.
    #[must_use]
    pub fn labels(&self) -> &ObservationField<Labels> {
        &self.labels
    }
    /// Returns the wire-level volume UID observation or its observation state.
    #[must_use]
    pub fn uid(&self) -> &ObservationField<VolumeOwnerIdWireValue> {
        &self.uid
    }
    /// Returns the wire-level volume GID observation or its observation state.
    #[must_use]
    pub fn gid(&self) -> &ObservationField<VolumeOwnerIdWireValue> {
        &self.gid
    }
    /// Returns the effective volume driver name.
    #[must_use]
    pub fn driver(&self) -> &ObservationField<String> {
        &self.driver
    }
    /// Returns the effective creation timestamp.
    #[must_use]
    pub fn created_at(&self) -> &ObservationField<NativeTimestamp> {
        &self.created_at
    }
    /// Returns whether Podman reported this as an anonymous volume.
    #[must_use]
    pub fn anonymous(&self) -> &ObservationField<bool> {
        &self.anonymous
    }
}

/// Image-specific native observations.
#[derive(Clone, Eq, PartialEq)]
pub struct ImageObservation {
    labels: ObservationField<Labels>,
    repo_tags: ObservationField<Vec<String>>,
    repo_digests: ObservationField<Vec<String>>,
    environment: ObservationField<ProtectedEnvironment>,
    digest: ObservationField<String>,
    created: ObservationField<NativeTimestamp>,
    author: ObservationField<String>,
    architecture: ObservationField<String>,
    operating_system: ObservationField<String>,
    manifest_type: ObservationField<String>,
}

pub(crate) struct ImageObservationFields {
    pub(crate) labels: ObservationField<Labels>,
    pub(crate) repo_tags: ObservationField<Vec<String>>,
    pub(crate) repo_digests: ObservationField<Vec<String>>,
    pub(crate) environment: ObservationField<ProtectedEnvironment>,
    pub(crate) digest: ObservationField<String>,
    pub(crate) created: ObservationField<NativeTimestamp>,
    pub(crate) author: ObservationField<String>,
    pub(crate) architecture: ObservationField<String>,
    pub(crate) operating_system: ObservationField<String>,
    pub(crate) manifest_type: ObservationField<String>,
}
observation_debug!(
    ImageObservation,
    labels,
    repo_tags,
    repo_digests,
    environment,
    digest,
    created,
    author,
    architecture,
    operating_system,
    manifest_type
);

impl ImageObservation {
    pub(crate) fn new(fields: ImageObservationFields) -> Self {
        let ImageObservationFields {
            labels,
            repo_tags,
            repo_digests,
            environment,
            digest,
            created,
            author,
            architecture,
            operating_system,
            manifest_type,
        } = fields;
        Self {
            labels,
            repo_tags,
            repo_digests,
            environment,
            digest,
            created,
            author,
            architecture,
            operating_system,
            manifest_type,
        }
    }
    /// Returns the configured image labels or their observation state.
    #[must_use]
    pub fn labels(&self) -> &ObservationField<Labels> {
        &self.labels
    }
    /// Returns locally resolved repository tags or their observation state.
    #[must_use]
    pub fn repo_tags(&self) -> &ObservationField<Vec<String>> {
        &self.repo_tags
    }
    /// Returns locally resolved repository digests or their observation state.
    #[must_use]
    pub fn repo_digests(&self) -> &ObservationField<Vec<String>> {
        &self.repo_digests
    }
    /// Returns protected image-environment observations or their observation state.
    #[must_use]
    pub fn environment(&self) -> &ObservationField<ProtectedEnvironment> {
        &self.environment
    }
    /// Returns the effective image digest.
    #[must_use]
    pub fn digest(&self) -> &ObservationField<String> {
        &self.digest
    }
    /// Returns the effective image creation timestamp.
    #[must_use]
    pub fn created(&self) -> &ObservationField<NativeTimestamp> {
        &self.created
    }
    /// Returns the configured image author metadata.
    #[must_use]
    pub fn author(&self) -> &ObservationField<String> {
        &self.author
    }
    /// Returns the effective image architecture.
    #[must_use]
    pub fn architecture(&self) -> &ObservationField<String> {
        &self.architecture
    }
    /// Returns the effective image operating-system name.
    #[must_use]
    pub fn operating_system(&self) -> &ObservationField<String> {
        &self.operating_system
    }
    /// Returns the effective image manifest media type.
    #[must_use]
    pub fn manifest_type(&self) -> &ObservationField<String> {
        &self.manifest_type
    }
}

/// Secret metadata observations.  Secret payload bytes are never represented.
#[derive(Clone, Eq, PartialEq)]
pub struct SecretObservation {
    labels: ObservationField<Labels>,
    driver: ObservationField<NativeSecretDriverObservation>,
    created_at: ObservationField<NativeTimestamp>,
    updated_at: ObservationField<NativeTimestamp>,
}
observation_debug!(SecretObservation, labels, driver, created_at, updated_at);

impl SecretObservation {
    pub(crate) fn new(
        labels: ObservationField<Labels>,
        driver: ObservationField<NativeSecretDriverObservation>,
        created_at: ObservationField<NativeTimestamp>,
        updated_at: ObservationField<NativeTimestamp>,
    ) -> Self {
        Self {
            labels,
            driver,
            created_at,
            updated_at,
        }
    }
    /// Returns the configured secret labels or their observation state.
    #[must_use]
    pub fn labels(&self) -> &ObservationField<Labels> {
        &self.labels
    }
    /// Returns the secret-driver metadata or its observation state.
    #[must_use]
    pub fn driver(&self) -> &ObservationField<NativeSecretDriverObservation> {
        &self.driver
    }
    /// Returns the effective creation timestamp.
    #[must_use]
    pub fn created_at(&self) -> &ObservationField<NativeTimestamp> {
        &self.created_at
    }
    /// Returns the effective last-update timestamp.
    #[must_use]
    pub fn updated_at(&self) -> &ObservationField<NativeTimestamp> {
        &self.updated_at
    }
}

/// Resource-kind-specific observation payload.
#[derive(Clone, Eq, PartialEq)]
#[non_exhaustive]
#[allow(clippy::large_enum_variant)] // kind-safe public enum avoids heap allocation at every observation access.
pub enum ResourceDetails {
    /// Container-only fields.
    Container(ContainerObservation),
    /// Pod-only fields.
    Pod(PodObservation),
    /// Network-only fields.
    Network(NetworkObservation),
    /// Volume-only fields.
    Volume(VolumeObservation),
    /// Image-only fields.
    Image(ImageObservation),
    /// Secret metadata-only fields.
    Secret(SecretObservation),
}

impl fmt::Debug for ResourceDetails {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Container(value) => formatter
                .debug_tuple("ResourceDetails::Container")
                .field(value)
                .finish(),
            Self::Pod(value) => formatter.debug_tuple("ResourceDetails::Pod").field(value).finish(),
            Self::Network(value) => formatter.debug_tuple("ResourceDetails::Network").field(value).finish(),
            Self::Volume(value) => formatter.debug_tuple("ResourceDetails::Volume").field(value).finish(),
            Self::Image(value) => formatter.debug_tuple("ResourceDetails::Image").field(value).finish(),
            Self::Secret(value) => formatter.debug_tuple("ResourceDetails::Secret").field(value).finish(),
        }
    }
}

impl ResourceDetails {
    /// Returns the exact resource kind carried by this variant.
    #[must_use]
    pub const fn kind(&self) -> ResourceKind {
        match self {
            Self::Container(_) => ResourceKind::Container,
            Self::Pod(_) => ResourceKind::Pod,
            Self::Network(_) => ResourceKind::Network,
            Self::Volume(_) => ResourceKind::Volume,
            Self::Image(_) => ResourceKind::Image,
            Self::Secret(_) => ResourceKind::Secret,
        }
    }
}

/// One complete or partial typed native resource observation.
#[derive(Clone, Eq, PartialEq)]
pub struct ResourceObservation {
    header: ObservationHeader,
    details: ResourceDetails,
}

impl ResourceObservation {
    pub(crate) fn try_new(header: ObservationHeader, details: ResourceDetails) -> Result<Self, Diagnostic> {
        if header.identity().kind() != details.kind() {
            return Err(Diagnostic::new(DiagnosticCode::ResourceMalformed));
        }
        Ok(Self { header, details })
    }

    pub(crate) fn incomplete(header: ObservationHeader) -> Self {
        let details = incomplete_details(header.identity().kind(), header.state());
        Self { header, details }
    }

    /// Returns resource-wide identity, evidence, findings, and completeness information.
    #[must_use]
    pub fn header(&self) -> &ObservationHeader {
        &self.header
    }
    /// Returns a kind-safe resource-specific payload.
    #[must_use]
    pub fn details(&self) -> &ResourceDetails {
        &self.details
    }

    pub(crate) fn header_mut(&mut self) -> &mut ObservationHeader {
        &mut self.header
    }

    pub(crate) fn relationships(&self) -> Option<&ObservationField<Vec<NativeRelationship>>> {
        match &self.details {
            ResourceDetails::Container(value) => Some(value.relationships()),
            ResourceDetails::Pod(value) => Some(value.relationships()),
            _ => None,
        }
    }

    pub(crate) fn labels(&self) -> &ObservationField<Labels> {
        match &self.details {
            ResourceDetails::Container(value) => value.labels(),
            ResourceDetails::Pod(value) => value.labels(),
            ResourceDetails::Network(value) => value.labels(),
            ResourceDetails::Volume(value) => value.labels(),
            ResourceDetails::Image(value) => value.labels(),
            ResourceDetails::Secret(value) => value.labels(),
        }
    }

    pub(crate) fn image_repo_tags(&self) -> Option<&ObservationField<Vec<String>>> {
        match &self.details {
            ResourceDetails::Image(value) => Some(value.repo_tags()),
            _ => None,
        }
    }

    pub(crate) fn image_repo_digests(&self) -> Option<&ObservationField<Vec<String>>> {
        match &self.details {
            ResourceDetails::Image(value) => Some(value.repo_digests()),
            _ => None,
        }
    }
}

fn incomplete_field<T>(state: ResourceObservationState) -> ObservationField<T> {
    if state == ResourceObservationState::Malformed {
        ObservationField::Malformed
    } else {
        ObservationField::Unavailable
    }
}

fn incomplete_details(kind: ResourceKind, state: ResourceObservationState) -> ResourceDetails {
    match kind {
        ResourceKind::Container => ResourceDetails::Container(ContainerObservation::new(
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
        )),
        ResourceKind::Pod => ResourceDetails::Pod(PodObservation::new(
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
        )),
        ResourceKind::Network => ResourceDetails::Network(NetworkObservation::new(
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
        )),
        ResourceKind::Volume => ResourceDetails::Volume(VolumeObservation::new(
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
        )),
        ResourceKind::Image => ResourceDetails::Image(ImageObservation::new(ImageObservationFields {
            labels: incomplete_field(state),
            repo_tags: incomplete_field(state),
            repo_digests: incomplete_field(state),
            environment: incomplete_field(state),
            digest: incomplete_field(state),
            created: incomplete_field(state),
            author: incomplete_field(state),
            architecture: incomplete_field(state),
            operating_system: incomplete_field(state),
            manifest_type: incomplete_field(state),
        })),
        ResourceKind::Secret => ResourceDetails::Secret(SecretObservation::new(
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
            incomplete_field(state),
        )),
    }
}

impl fmt::Debug for ResourceObservation {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("ResourceObservation")
            .field("identity", self.header.identity())
            .field("state", &self.header.state())
            .field("finding_count", &self.header.findings().len())
            .field("unmodelled_field_count", &self.header.unmodelled_fields().len())
            .field("detail_kind", &self.details.kind())
            .finish()
    }
}