panlabel 0.7.0

The universal annotation converter
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
//! Conversion report types for tracking lossiness and policy decisions.
//!
//! This module provides structured reporting for format conversions,
//! similar to how `validation::ValidationReport` tracks dataset issues.

use serde::Serialize;
use std::fmt;

/// A report generated during format conversion.
///
/// Tracks input/output counts, lossiness warnings, and policy decisions
/// to help users understand exactly what happened during conversion.
#[derive(Clone, Debug, Default, Serialize)]
pub struct ConversionReport {
    /// Source format name.
    pub from: String,
    /// Target format name.
    pub to: String,
    /// Counts from the input dataset.
    pub input: ConversionCounts,
    /// Counts in the output (may differ if images are dropped, etc.).
    pub output: ConversionCounts,
    /// Issues discovered during conversion analysis.
    pub issues: Vec<ConversionIssue>,
}

impl ConversionReport {
    /// Create a new empty report for a conversion between formats.
    pub fn new(from: impl Into<String>, to: impl Into<String>) -> Self {
        Self {
            from: from.into(),
            to: to.into(),
            ..Default::default()
        }
    }

    /// Add an issue to the report.
    pub fn add(&mut self, issue: ConversionIssue) {
        self.issues.push(issue);
    }

    /// Count of warning-level issues (true lossiness).
    pub fn warning_count(&self) -> usize {
        self.issues
            .iter()
            .filter(|i| i.severity == ConversionSeverity::Warning)
            .count()
    }

    /// Count of info-level issues (policy decisions, notes).
    pub fn info_count(&self) -> usize {
        self.issues
            .iter()
            .filter(|i| i.severity == ConversionSeverity::Info)
            .count()
    }

    /// Returns true if this conversion would lose information.
    ///
    /// A conversion is lossy if it has any warning-level issues.
    pub fn is_lossy(&self) -> bool {
        self.warning_count() > 0
    }
}

impl fmt::Display for ConversionReport {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        // Always show counts
        writeln!(
            f,
            "  {} images, {} categories, {} annotations",
            self.input.images, self.input.categories, self.input.annotations
        )?;

        // Show output counts if they differ from input
        if self.output != self.input {
            writeln!(
                f,
                "  output: {} images, {} categories, {} annotations",
                self.output.images, self.output.categories, self.output.annotations
            )?;
        }

        // Show issues if any
        if !self.issues.is_empty() {
            let warnings = self.warning_count();
            let infos = self.info_count();

            if warnings > 0 {
                writeln!(f)?;
                writeln!(f, "Warnings ({}):", warnings)?;
                for issue in self
                    .issues
                    .iter()
                    .filter(|i| i.severity == ConversionSeverity::Warning)
                {
                    writeln!(f, "  - [{}] {}", issue.code.as_str(), issue.message)?;
                }
            }

            if infos > 0 {
                writeln!(f)?;
                writeln!(f, "Notes ({}):", infos)?;
                for issue in self
                    .issues
                    .iter()
                    .filter(|i| i.severity == ConversionSeverity::Info)
                {
                    writeln!(f, "  - [{}] {}", issue.code.as_str(), issue.message)?;
                }
            }
        }

        Ok(())
    }
}

/// Counts of dataset elements.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
pub struct ConversionCounts {
    pub images: usize,
    pub categories: usize,
    pub annotations: usize,
}

/// A single issue discovered during conversion analysis.
#[derive(Clone, Debug, Serialize)]
pub struct ConversionIssue {
    pub severity: ConversionSeverity,
    pub stage: ConversionStage,
    pub code: ConversionIssueCode,
    pub message: String,
}

impl ConversionIssue {
    /// Create a warning-level issue from lossiness analysis.
    pub fn warning(code: ConversionIssueCode, message: impl Into<String>) -> Self {
        Self {
            severity: ConversionSeverity::Warning,
            stage: ConversionStage::Analysis,
            code,
            message: message.into(),
        }
    }

    /// Create an info-level issue for a source reader policy.
    pub fn reader_info(code: ConversionIssueCode, message: impl Into<String>) -> Self {
        Self {
            severity: ConversionSeverity::Info,
            stage: ConversionStage::SourceReader,
            code,
            message: message.into(),
        }
    }

    /// Create an info-level issue for a target writer policy.
    pub fn writer_info(code: ConversionIssueCode, message: impl Into<String>) -> Self {
        Self {
            severity: ConversionSeverity::Info,
            stage: ConversionStage::TargetWriter,
            code,
            message: message.into(),
        }
    }

    /// Create an info-level issue (generic, for backward compatibility).
    pub fn info(code: ConversionIssueCode, message: impl Into<String>) -> Self {
        Self {
            severity: ConversionSeverity::Info,
            stage: ConversionStage::Analysis,
            code,
            message: message.into(),
        }
    }
}

/// The pipeline stage where a conversion issue originates.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ConversionStage {
    /// Lossiness analysis (warnings about data loss).
    Analysis,
    /// Source format reader policy.
    SourceReader,
    /// Target format writer policy.
    TargetWriter,
}

/// Severity level for conversion issues.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ConversionSeverity {
    /// A warning indicates information loss; requires `--allow-lossy`.
    Warning,
    /// An info note describes policy decisions; does not block conversion.
    Info,
}

/// Stable issue codes for programmatic consumption.
///
/// These codes are part of the JSON schema and should remain stable.
/// Use [`ConversionIssueCode::as_str()`] for the canonical string form
/// shared by both text and JSON output.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum ConversionIssueCode {
    // IR -> TFOD lossiness
    /// Dataset info/metadata will be dropped.
    DropDatasetInfo,
    /// Licenses will be dropped.
    DropLicenses,
    /// Image license_id and/or date_captured will be dropped.
    DropImageMetadata,
    /// Category supercategory will be dropped.
    DropCategorySupercategory,
    /// Annotation confidence scores will be dropped.
    DropAnnotationConfidence,
    /// Annotation attributes will be dropped.
    DropAnnotationAttributes,
    /// Images without annotations will not appear in output.
    DropImagesWithoutAnnotations,
    /// Categories not referenced by annotations will not appear in output.
    DropUnusedCategories,

    // IR -> COCO lossiness
    /// Dataset info.name has no COCO equivalent.
    DropDatasetInfoName,
    /// Annotation attributes (other than area/iscrowd) may not be preserved by COCO tools.
    CocoAttributesMayNotBePreserved,

    // IR -> COCO policy (Info level — writer behaviors)
    /// COCO writer sorts all lists (licenses, images, categories, annotations) by ID.
    CocoWriterDeterministicOrder,
    /// COCO writer maps IR confidence to COCO score field.
    CocoWriterScoreMapping,
    /// COCO writer maps area/iscrowd via IR annotation attributes.
    CocoWriterAreaIscrowdMapping,
    /// COCO writer emits empty segmentation arrays for detection-only output.
    CocoWriterEmptySegmentation,
    /// COCO reader maps score to IR confidence and area/iscrowd to annotation attributes.
    CocoReaderAttributeMapping,

    // IR -> HF lossiness
    /// HF metadata cannot represent all IR dataset metadata/licensing fields.
    HfMetadataLost,
    /// HF metadata loses annotation/image attributes not in the flat schema.
    HfAttributesLost,
    /// HF metadata does not represent annotation confidence scores.
    HfConfidenceLost,

    // HF policy (Info level)
    /// HF reader object-container column precedence.
    HfReaderObjectContainerPrecedence,
    /// HF reader bbox interpretation depends on --hf-bbox-format.
    HfReaderBboxFormatDependence,

    // Label Studio policy (Info level — writer behaviors)
    /// Label Studio writer routes confident annotations to predictions block.
    LabelStudioWriterConfidenceRouting,

    // YOLO policy (Info level — writer behaviors)
    /// YOLO writer orders images and labels deterministically.
    YoloWriterDeterministicOrder,
    /// YOLO writer does not copy image binaries; only label files are written.
    YoloWriterNoImageCopy,
    /// YOLO writer emits data.yaml with class names and directory paths.
    YoloWriterDataYamlPolicy,

    // Policy decisions (Info level — reader/writer behaviors)
    /// TFOD reader assigns IDs by lexicographic ordering.
    TfodReaderIdAssignment,
    /// TFOD writer orders rows by annotation ID.
    TfodWriterRowOrder,
    /// TFRecord reader assigns IDs deterministically.
    TfrecordReaderIdAssignment,
    /// TFRecord reader payload support/mapping policy.
    TfrecordReaderPayloadPolicy,
    /// TFRecord writer emits Examples in deterministic order.
    TfrecordWriterExampleOrder,
    /// TFRecord writer payload support/mapping policy.
    TfrecordWriterPayloadPolicy,
    /// YOLO reader assigns IDs by deterministic ordering.
    YoloReaderIdAssignment,
    /// YOLO reader class-map precedence/source.
    YoloReaderClassMapSource,
    /// YOLO reader split-aware layout handling (merge or selection).
    YoloReaderSplitHandling,
    /// YOLO writer assigns class indices by category ID order.
    YoloWriterClassOrder,
    /// YOLO writer creates empty label files for images without annotations.
    YoloWriterEmptyLabelFiles,
    /// YOLO writer outputs normalized floats at 6 decimal places.
    YoloWriterFloatPrecision,
    /// YOLO Keras-style TXT reader deterministic ID assignment policy.
    YoloKerasTxtReaderIdAssignment,
    /// YOLO Keras-style TXT reader class-map source policy.
    YoloKerasTxtReaderClassMapSource,
    /// YOLO Keras-style TXT reader image resolution policy.
    YoloKerasTxtReaderImageResolution,
    /// YOLO Keras-style TXT writer class ID assignment policy.
    YoloKerasTxtWriterClassOrder,
    /// YOLO Keras-style TXT writer deterministic ordering policy.
    YoloKerasTxtWriterDeterministicOrder,
    /// YOLO Keras-style TXT writer empty row policy.
    YoloKerasTxtWriterEmptyRows,
    /// YOLO Keras-style TXT writer does not copy images.
    YoloKerasTxtWriterNoImageCopy,
    /// VOC reader assigns IDs by deterministic ordering.
    VocReaderIdAssignment,
    /// VOC reader maps pose/truncated/difficult/occluded to IR attributes.
    VocReaderAttributeMapping,
    /// VOC reader keeps bndbox coordinates exactly as provided (no offset adjustment).
    VocReaderCoordinatePolicy,
    /// VOC reader stores depth as an image attribute; depth != 3 may need downstream care.
    VocReaderDepthHandling,
    /// VOC writer file layout and XML naming policy.
    VocWriterFileLayout,
    /// VOC writer creates JPEGImages/README.txt and does not copy images.
    VocWriterNoImageCopy,
    /// VOC writer normalizes boolean fields (truncated/difficult/occluded).
    VocWriterBoolNormalization,
    /// Label Studio reader converted rotated boxes to axis-aligned envelopes.
    LabelStudioRotationDropped,
    /// Label Studio reader ID assignment policy.
    LabelStudioReaderIdAssignment,
    /// Label Studio reader image-reference policy.
    LabelStudioReaderImageRefPolicy,
    /// Label Studio writer default from_name/to_name policy.
    LabelStudioWriterFromToDefaults,

    // Labelbox policy (Info/Warning level)
    /// Labelbox reader deterministic ID assignment policy.
    LabelboxReaderIdAssignment,
    /// Labelbox reader data_row/media_attributes policy.
    LabelboxReaderImageMetadata,
    /// Labelbox reader converted polygons to bbox envelopes.
    LabelboxPolygonEnvelopeApplied,
    /// Labelbox reader skipped unsupported non-detection objects.
    LabelboxUnsupportedObjectsSkipped,
    /// Labelbox writer JSON vs NDJSON output policy.
    LabelboxWriterFormatPolicy,
    /// Labelbox writer emits bbox-only object rows.
    LabelboxWriterRectanglePolicy,
    /// Labelbox writer does not copy images.
    LabelboxWriterNoImageCopy,

    // Scale AI policy (Info/Warning level)
    /// Scale AI reader deterministic ID assignment policy.
    ScaleAiReaderIdAssignment,
    /// Scale AI reader image-reference/dimension policy.
    ScaleAiReaderImageMetadata,
    /// Scale AI reader converted polygon/rotated geometry to bbox envelopes.
    ScaleAiGeometryEnvelopeApplied,
    /// Scale AI writer deterministic ordering policy.
    ScaleAiWriterDeterministicOrder,
    /// Scale AI writer emits bbox-only response annotations.
    ScaleAiWriterRectanglePolicy,
    /// Scale AI writer does not copy images.
    ScaleAiWriterNoImageCopy,

    // Unity Perception policy (Info/Warning level)
    /// Unity Perception reader deterministic ID assignment policy.
    UnityPerceptionReaderIdAssignment,
    /// Unity Perception reader image/capture metadata policy.
    UnityPerceptionReaderImageMetadata,
    /// Unity Perception reader skipped unsupported non-bbox annotations.
    UnityPerceptionUnsupportedAnnotationsSkipped,
    /// Unity Perception writer directory layout policy.
    UnityPerceptionWriterDirectoryLayout,
    /// Unity Perception writer bbox-only annotation policy.
    UnityPerceptionWriterRectanglePolicy,
    /// Unity Perception writer does not copy images.
    UnityPerceptionWriterNoImageCopy,

    /// CVAT reader deterministic ID assignment policy.
    CvatReaderIdAssignment,
    /// CVAT reader coordinate + attribute mapping policy.
    CvatReaderAttributePolicy,
    /// CVAT writer default metadata block policy.
    CvatWriterMetaDefaults,
    /// CVAT writer deterministic ordering policy (images by filename, boxes by annotation ID).
    CvatWriterDeterministicOrder,
    /// CVAT writer reassigns image IDs sequentially (original cvat_image_id not preserved).
    CvatWriterImageIdReassignment,
    /// CVAT writer defaults missing source attribute to "manual".
    CvatWriterSourceDefault,
    /// CVAT writer drops unused categories from <meta><labels>.
    CvatWriterDropUnusedCategories,
    /// HF reader category-name resolution precedence.
    HfReaderCategoryResolution,
    /// HF writer deterministic output ordering policy.
    HfWriterDeterministicOrder,

    // SageMaker Ground Truth policy (Info level)
    /// SageMaker reader deterministic ID assignment policy.
    SagemakerReaderIdAssignment,
    /// SageMaker reader label attribute detection policy.
    SagemakerReaderLabelAttributeDetection,
    /// SageMaker reader class-map/category resolution policy.
    SagemakerReaderClassMapResolution,
    /// SageMaker writer deterministic ordering policy.
    SagemakerWriterDeterministicOrder,
    /// SageMaker writer class-map/class_id assignment policy.
    SagemakerWriterClassMapPolicy,
    /// SageMaker writer metadata default policy.
    SagemakerWriterMetadataDefaults,
    /// SageMaker writer does not copy images.
    SagemakerWriterNoImageCopy,

    // LabelMe policy (Info level)
    /// LabelMe reader deterministic ID assignment policy.
    LabelmeReaderIdAssignment,
    /// LabelMe reader file-name/path derivation policy.
    LabelmeReaderPathPolicy,
    /// LabelMe reader polygon envelope behavior.
    LabelmePolygonEnvelopeApplied,
    /// LabelMe writer canonical file layout.
    LabelmeWriterFileLayout,
    /// LabelMe writer emits all annotations as rectangles.
    LabelmeWriterRectanglePolicy,
    /// LabelMe writer does not copy images.
    LabelmeWriterNoImageCopy,

    // SuperAnnotate policy (Info level)
    /// SuperAnnotate reader deterministic ID assignment policy.
    SuperannotateReaderIdAssignment,
    /// SuperAnnotate reader polygon/rotated-geometry envelope behavior.
    SuperannotatePolygonEnvelopeApplied,
    /// SuperAnnotate writer canonical file layout.
    SuperannotateWriterFileLayout,
    /// SuperAnnotate writer emits all annotations as bboxes.
    SuperannotateWriterRectanglePolicy,
    /// SuperAnnotate writer does not copy images.
    SuperannotateWriterNoImageCopy,

    // Supervisely policy (Info level)
    /// Supervisely reader deterministic ID assignment policy.
    SuperviselyReaderIdAssignment,
    /// Supervisely reader polygon envelope behavior.
    SuperviselyPolygonEnvelopeApplied,
    /// Supervisely writer canonical project layout.
    SuperviselyWriterProjectLayout,
    /// Supervisely writer emits all annotations as rectangles.
    SuperviselyWriterRectanglePolicy,
    /// Supervisely writer does not copy images.
    SuperviselyWriterNoImageCopy,

    // Cityscapes policy (Info level)
    /// Cityscapes reader deterministic ID assignment policy.
    CityscapesReaderIdAssignment,
    /// Cityscapes reader polygon envelope behavior.
    CityscapesPolygonEnvelopeApplied,
    /// Cityscapes reader skipped deleted/ignored/stuff labels.
    CityscapesSkippedLabels,
    /// Cityscapes writer canonical gtFine layout.
    CityscapesWriterGtFineLayout,
    /// Cityscapes writer emits bbox rectangles as four-point polygons.
    CityscapesWriterRectanglePolygonPolicy,
    /// Cityscapes writer does not copy images.
    CityscapesWriterNoImageCopy,

    // Marmot policy (Info level)
    /// Marmot reader deterministic ID assignment policy.
    MarmotReaderIdAssignment,
    /// Marmot reader hex-double coordinate transform policy.
    MarmotReaderHexCoordinateTransform,
    /// Marmot reader requires companion images for pixel dimensions.
    MarmotReaderCompanionImageRequired,
    /// Marmot writer emits deterministic minimal XML.
    MarmotWriterMinimalXml,
    /// Marmot writer does not copy images.
    MarmotWriterNoImageCopy,

    // CreateML policy (Info level)
    /// CreateML reader deterministic ID assignment policy.
    CreatemlReaderIdAssignment,
    /// CreateML reader image resolution precedence.
    CreatemlReaderImageResolution,
    /// CreateML writer deterministic ordering policy.
    CreatemlWriterDeterministicOrder,
    /// CreateML writer center-based coordinate mapping.
    CreatemlWriterCoordinateMapping,
    /// CreateML writer does not copy images.
    CreatemlWriterNoImageCopy,

    // KITTI policy (Info level)
    /// KITTI reader deterministic ID assignment policy.
    KittiReaderIdAssignment,
    /// KITTI reader maps non-bbox fields to IR attributes.
    KittiReaderFieldMapping,
    /// KITTI reader image resolution precedence.
    KittiReaderImageResolution,
    /// KITTI writer canonical file layout.
    KittiWriterFileLayout,
    /// KITTI writer uses default values for missing KITTI-specific attributes.
    KittiWriterDefaultFieldValues,
    /// KITTI writer deterministic ordering policy.
    KittiWriterDeterministicOrder,
    /// KITTI writer does not copy images.
    KittiWriterNoImageCopy,

    // VIA policy (Info level)
    /// VIA reader deterministic ID assignment policy.
    ViaReaderIdAssignment,
    /// VIA reader label resolution precedence.
    ViaReaderLabelResolution,
    /// VIA reader image resolution precedence.
    ViaReaderImageResolution,
    /// VIA writer deterministic ordering policy.
    ViaWriterDeterministicOrder,
    /// VIA writer canonical label attribute key.
    ViaWriterLabelAttributeKey,
    /// VIA writer does not copy images.
    ViaWriterNoImageCopy,

    // VoTT CSV policy (Info level)
    /// VoTT CSV reader deterministic ID assignment policy.
    VottCsvReaderIdAssignment,
    /// VoTT CSV reader resolves image dimensions from local files.
    VottCsvReaderImageResolution,
    /// VoTT CSV writer deterministic row ordering.
    VottCsvWriterRowOrder,
    /// VoTT CSV writer does not copy images.
    VottCsvWriterNoImageCopy,

    // VoTT JSON policy (Info level)
    /// VoTT JSON reader deterministic ID assignment policy.
    VottJsonReaderIdAssignment,
    /// VoTT JSON reader converted point geometry to bbox envelopes.
    VottJsonPolygonEnvelopeApplied,
    /// VoTT JSON writer deterministic ordering policy.
    VottJsonWriterDeterministicOrder,
    /// VoTT JSON writer rectangle-region policy.
    VottJsonWriterRectanglePolicy,
    /// VoTT JSON writer does not copy images.
    VottJsonWriterNoImageCopy,

    // IBM Cloud Annotations policy (Info level)
    /// IBM Cloud Annotations reader deterministic ID assignment policy.
    CloudAnnotationsReaderIdAssignment,
    /// IBM Cloud Annotations reader resolves image dimensions from local files.
    CloudAnnotationsReaderImageResolution,
    /// IBM Cloud Annotations writer deterministic ordering policy.
    CloudAnnotationsWriterDeterministicOrder,
    /// IBM Cloud Annotations writer normalized coordinate policy.
    CloudAnnotationsWriterNormalizedCoordinates,
    /// IBM Cloud Annotations writer does not copy images.
    CloudAnnotationsWriterNoImageCopy,

    // RetinaNet policy (Info level)
    /// RetinaNet reader deterministic ID assignment policy.
    RetinanetReaderIdAssignment,
    /// RetinaNet reader image resolution precedence.
    RetinanetReaderImageResolution,
    /// RetinaNet reader empty-row handling.
    RetinanetReaderEmptyRowHandling,
    /// RetinaNet writer deterministic ordering policy.
    RetinanetWriterDeterministicOrder,
    /// RetinaNet writer empty-row convention for unannotated images.
    RetinanetWriterEmptyRows,
    /// RetinaNet writer does not copy images.
    RetinanetWriterNoImageCopy,

    // OpenImages policy (Info level)
    /// OpenImages reader deterministic ID assignment policy.
    OpenimagesReaderIdAssignment,
    /// OpenImages reader resolves image dimensions from local files.
    OpenimagesReaderImageResolution,
    /// OpenImages writer deterministic ordering policy.
    OpenimagesWriterDeterministicOrder,

    DatumaroReaderIdAssignment,
    DatumaroWriterDeterministicOrder,
    WiderFaceReaderIdAssignment,
    WiderFaceWriterFileLayout,
    Oidv4ReaderIdAssignment,
    Oidv4WriterFileLayout,
    Bdd100kReaderIdAssignment,
    Bdd100kWriterDeterministicOrder,
    V7DarwinReaderIdAssignment,
    V7DarwinWriterDeterministicOrder,
    EdgeImpulseReaderIdAssignment,
    EdgeImpulseWriterDeterministicOrder,
    OpenlabelReaderIdAssignment,
    OpenlabelWriterFrameLayout,
    ViaCsvReaderIdAssignment,
    ViaCsvWriterDeterministicOrder,

    // Kaggle Wheat policy (Info level)
    /// Kaggle Wheat reader deterministic ID assignment policy.
    KaggleWheatReaderIdAssignment,
    /// Kaggle Wheat writer deterministic ordering and bbox formatting.
    KaggleWheatWriterDeterministicOrder,

    // Kaggle Wheat lossiness
    /// Multiple categories collapsed to single class for single-class format.
    CollapseMultipleCategoriesToSingleClass,

    // AutoML Vision policy (Info level)
    /// AutoML Vision reader deterministic ID assignment policy.
    AutomlVisionReaderIdAssignment,
    /// AutoML Vision reader resolves image dimensions from local files.
    AutomlVisionReaderImageResolution,
    /// AutoML Vision writer deterministic ordering policy.
    AutomlVisionWriterDeterministicOrder,

    // Udacity policy (Info level)
    /// Udacity reader deterministic ID assignment policy.
    UdacityReaderIdAssignment,
    /// Udacity writer deterministic row ordering.
    UdacityWriterRowOrder,
}

impl ConversionIssueCode {
    /// All known issue codes, for drift-prevention testing.
    pub const ALL: &'static [ConversionIssueCode] = &[
        Self::DropDatasetInfo,
        Self::DropLicenses,
        Self::DropImageMetadata,
        Self::DropCategorySupercategory,
        Self::DropAnnotationConfidence,
        Self::DropAnnotationAttributes,
        Self::DropImagesWithoutAnnotations,
        Self::DropUnusedCategories,
        Self::DropDatasetInfoName,
        Self::CocoAttributesMayNotBePreserved,
        Self::CocoWriterDeterministicOrder,
        Self::CocoWriterScoreMapping,
        Self::CocoWriterAreaIscrowdMapping,
        Self::CocoWriterEmptySegmentation,
        Self::CocoReaderAttributeMapping,
        Self::HfMetadataLost,
        Self::HfAttributesLost,
        Self::HfConfidenceLost,
        Self::HfReaderObjectContainerPrecedence,
        Self::HfReaderBboxFormatDependence,
        Self::LabelStudioWriterConfidenceRouting,
        Self::YoloWriterDeterministicOrder,
        Self::YoloWriterNoImageCopy,
        Self::YoloWriterDataYamlPolicy,
        Self::TfodReaderIdAssignment,
        Self::TfodWriterRowOrder,
        Self::TfrecordReaderIdAssignment,
        Self::TfrecordReaderPayloadPolicy,
        Self::TfrecordWriterExampleOrder,
        Self::TfrecordWriterPayloadPolicy,
        Self::YoloReaderIdAssignment,
        Self::YoloReaderClassMapSource,
        Self::YoloReaderSplitHandling,
        Self::YoloWriterClassOrder,
        Self::YoloWriterEmptyLabelFiles,
        Self::YoloWriterFloatPrecision,
        Self::YoloKerasTxtReaderIdAssignment,
        Self::YoloKerasTxtReaderClassMapSource,
        Self::YoloKerasTxtReaderImageResolution,
        Self::YoloKerasTxtWriterClassOrder,
        Self::YoloKerasTxtWriterDeterministicOrder,
        Self::YoloKerasTxtWriterEmptyRows,
        Self::YoloKerasTxtWriterNoImageCopy,
        Self::VocReaderIdAssignment,
        Self::VocReaderAttributeMapping,
        Self::VocReaderCoordinatePolicy,
        Self::VocReaderDepthHandling,
        Self::VocWriterFileLayout,
        Self::VocWriterNoImageCopy,
        Self::VocWriterBoolNormalization,
        Self::LabelStudioRotationDropped,
        Self::LabelStudioReaderIdAssignment,
        Self::LabelStudioReaderImageRefPolicy,
        Self::LabelStudioWriterFromToDefaults,
        Self::LabelboxReaderIdAssignment,
        Self::LabelboxReaderImageMetadata,
        Self::LabelboxPolygonEnvelopeApplied,
        Self::LabelboxUnsupportedObjectsSkipped,
        Self::LabelboxWriterFormatPolicy,
        Self::LabelboxWriterRectanglePolicy,
        Self::LabelboxWriterNoImageCopy,
        Self::ScaleAiReaderIdAssignment,
        Self::ScaleAiReaderImageMetadata,
        Self::ScaleAiGeometryEnvelopeApplied,
        Self::ScaleAiWriterDeterministicOrder,
        Self::ScaleAiWriterRectanglePolicy,
        Self::ScaleAiWriterNoImageCopy,
        Self::UnityPerceptionReaderIdAssignment,
        Self::UnityPerceptionReaderImageMetadata,
        Self::UnityPerceptionUnsupportedAnnotationsSkipped,
        Self::UnityPerceptionWriterDirectoryLayout,
        Self::UnityPerceptionWriterRectanglePolicy,
        Self::UnityPerceptionWriterNoImageCopy,
        Self::CvatReaderIdAssignment,
        Self::CvatReaderAttributePolicy,
        Self::CvatWriterMetaDefaults,
        Self::CvatWriterDeterministicOrder,
        Self::CvatWriterImageIdReassignment,
        Self::CvatWriterSourceDefault,
        Self::CvatWriterDropUnusedCategories,
        Self::HfReaderCategoryResolution,
        Self::HfWriterDeterministicOrder,
        Self::SagemakerReaderIdAssignment,
        Self::SagemakerReaderLabelAttributeDetection,
        Self::SagemakerReaderClassMapResolution,
        Self::SagemakerWriterDeterministicOrder,
        Self::SagemakerWriterClassMapPolicy,
        Self::SagemakerWriterMetadataDefaults,
        Self::SagemakerWriterNoImageCopy,
        Self::LabelmeReaderIdAssignment,
        Self::LabelmeReaderPathPolicy,
        Self::LabelmePolygonEnvelopeApplied,
        Self::LabelmeWriterFileLayout,
        Self::LabelmeWriterRectanglePolicy,
        Self::LabelmeWriterNoImageCopy,
        Self::SuperannotateReaderIdAssignment,
        Self::SuperannotatePolygonEnvelopeApplied,
        Self::SuperannotateWriterFileLayout,
        Self::SuperannotateWriterRectanglePolicy,
        Self::SuperannotateWriterNoImageCopy,
        Self::SuperviselyReaderIdAssignment,
        Self::SuperviselyPolygonEnvelopeApplied,
        Self::SuperviselyWriterProjectLayout,
        Self::SuperviselyWriterRectanglePolicy,
        Self::SuperviselyWriterNoImageCopy,
        Self::CityscapesReaderIdAssignment,
        Self::CityscapesPolygonEnvelopeApplied,
        Self::CityscapesSkippedLabels,
        Self::CityscapesWriterGtFineLayout,
        Self::CityscapesWriterRectanglePolygonPolicy,
        Self::CityscapesWriterNoImageCopy,
        Self::MarmotReaderIdAssignment,
        Self::MarmotReaderHexCoordinateTransform,
        Self::MarmotReaderCompanionImageRequired,
        Self::MarmotWriterMinimalXml,
        Self::MarmotWriterNoImageCopy,
        Self::CreatemlReaderIdAssignment,
        Self::CreatemlReaderImageResolution,
        Self::CreatemlWriterDeterministicOrder,
        Self::CreatemlWriterCoordinateMapping,
        Self::CreatemlWriterNoImageCopy,
        Self::KittiReaderIdAssignment,
        Self::KittiReaderFieldMapping,
        Self::KittiReaderImageResolution,
        Self::KittiWriterFileLayout,
        Self::KittiWriterDefaultFieldValues,
        Self::KittiWriterDeterministicOrder,
        Self::KittiWriterNoImageCopy,
        Self::ViaReaderIdAssignment,
        Self::ViaReaderLabelResolution,
        Self::ViaReaderImageResolution,
        Self::ViaWriterDeterministicOrder,
        Self::ViaWriterLabelAttributeKey,
        Self::ViaWriterNoImageCopy,
        Self::VottCsvReaderIdAssignment,
        Self::VottCsvReaderImageResolution,
        Self::VottCsvWriterRowOrder,
        Self::VottCsvWriterNoImageCopy,
        Self::VottJsonReaderIdAssignment,
        Self::VottJsonPolygonEnvelopeApplied,
        Self::VottJsonWriterDeterministicOrder,
        Self::VottJsonWriterRectanglePolicy,
        Self::VottJsonWriterNoImageCopy,
        Self::CloudAnnotationsReaderIdAssignment,
        Self::CloudAnnotationsReaderImageResolution,
        Self::CloudAnnotationsWriterDeterministicOrder,
        Self::CloudAnnotationsWriterNormalizedCoordinates,
        Self::CloudAnnotationsWriterNoImageCopy,
        Self::RetinanetReaderIdAssignment,
        Self::RetinanetReaderImageResolution,
        Self::RetinanetReaderEmptyRowHandling,
        Self::RetinanetWriterDeterministicOrder,
        Self::RetinanetWriterEmptyRows,
        Self::RetinanetWriterNoImageCopy,
        Self::OpenimagesReaderIdAssignment,
        Self::OpenimagesReaderImageResolution,
        Self::OpenimagesWriterDeterministicOrder,
        Self::DatumaroReaderIdAssignment,
        Self::DatumaroWriterDeterministicOrder,
        Self::WiderFaceReaderIdAssignment,
        Self::WiderFaceWriterFileLayout,
        Self::Oidv4ReaderIdAssignment,
        Self::Oidv4WriterFileLayout,
        Self::Bdd100kReaderIdAssignment,
        Self::Bdd100kWriterDeterministicOrder,
        Self::V7DarwinReaderIdAssignment,
        Self::V7DarwinWriterDeterministicOrder,
        Self::EdgeImpulseReaderIdAssignment,
        Self::EdgeImpulseWriterDeterministicOrder,
        Self::OpenlabelReaderIdAssignment,
        Self::OpenlabelWriterFrameLayout,
        Self::ViaCsvReaderIdAssignment,
        Self::ViaCsvWriterDeterministicOrder,
        Self::KaggleWheatReaderIdAssignment,
        Self::KaggleWheatWriterDeterministicOrder,
        Self::CollapseMultipleCategoriesToSingleClass,
        Self::AutomlVisionReaderIdAssignment,
        Self::AutomlVisionReaderImageResolution,
        Self::AutomlVisionWriterDeterministicOrder,
        Self::UdacityReaderIdAssignment,
        Self::UdacityWriterRowOrder,
    ];

    /// Canonical stable string form, shared by text and JSON output.
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::DropDatasetInfo => "drop_dataset_info",
            Self::DropLicenses => "drop_licenses",
            Self::DropImageMetadata => "drop_image_metadata",
            Self::DropCategorySupercategory => "drop_category_supercategory",
            Self::DropAnnotationConfidence => "drop_annotation_confidence",
            Self::DropAnnotationAttributes => "drop_annotation_attributes",
            Self::DropImagesWithoutAnnotations => "drop_images_without_annotations",
            Self::DropUnusedCategories => "drop_unused_categories",
            Self::DropDatasetInfoName => "drop_dataset_info_name",
            Self::CocoAttributesMayNotBePreserved => "coco_attributes_may_not_be_preserved",
            Self::CocoWriterDeterministicOrder => "coco_writer_deterministic_order",
            Self::CocoWriterScoreMapping => "coco_writer_score_mapping",
            Self::CocoWriterAreaIscrowdMapping => "coco_writer_area_iscrowd_mapping",
            Self::CocoWriterEmptySegmentation => "coco_writer_empty_segmentation",
            Self::CocoReaderAttributeMapping => "coco_reader_attribute_mapping",
            Self::HfMetadataLost => "hf_metadata_lost",
            Self::HfAttributesLost => "hf_attributes_lost",
            Self::HfConfidenceLost => "hf_confidence_lost",
            Self::HfReaderObjectContainerPrecedence => "hf_reader_object_container_precedence",
            Self::HfReaderBboxFormatDependence => "hf_reader_bbox_format_dependence",
            Self::LabelStudioWriterConfidenceRouting => "label_studio_writer_confidence_routing",
            Self::YoloWriterDeterministicOrder => "yolo_writer_deterministic_order",
            Self::YoloWriterNoImageCopy => "yolo_writer_no_image_copy",
            Self::YoloWriterDataYamlPolicy => "yolo_writer_data_yaml_policy",
            Self::TfodReaderIdAssignment => "tfod_reader_id_assignment",
            Self::TfodWriterRowOrder => "tfod_writer_row_order",
            Self::TfrecordReaderIdAssignment => "tfrecord_reader_id_assignment",
            Self::TfrecordReaderPayloadPolicy => "tfrecord_reader_payload_policy",
            Self::TfrecordWriterExampleOrder => "tfrecord_writer_example_order",
            Self::TfrecordWriterPayloadPolicy => "tfrecord_writer_payload_policy",
            Self::YoloReaderIdAssignment => "yolo_reader_id_assignment",
            Self::YoloReaderClassMapSource => "yolo_reader_class_map_source",
            Self::YoloReaderSplitHandling => "yolo_reader_split_handling",
            Self::YoloWriterClassOrder => "yolo_writer_class_order",
            Self::YoloWriterEmptyLabelFiles => "yolo_writer_empty_label_files",
            Self::YoloWriterFloatPrecision => "yolo_writer_float_precision",
            Self::YoloKerasTxtReaderIdAssignment => "yolo_keras_txt_reader_id_assignment",
            Self::YoloKerasTxtReaderClassMapSource => "yolo_keras_txt_reader_class_map_source",
            Self::YoloKerasTxtReaderImageResolution => "yolo_keras_txt_reader_image_resolution",
            Self::YoloKerasTxtWriterClassOrder => "yolo_keras_txt_writer_class_order",
            Self::YoloKerasTxtWriterDeterministicOrder => {
                "yolo_keras_txt_writer_deterministic_order"
            }
            Self::YoloKerasTxtWriterEmptyRows => "yolo_keras_txt_writer_empty_rows",
            Self::YoloKerasTxtWriterNoImageCopy => "yolo_keras_txt_writer_no_image_copy",
            Self::VocReaderIdAssignment => "voc_reader_id_assignment",
            Self::VocReaderAttributeMapping => "voc_reader_attribute_mapping",
            Self::VocReaderCoordinatePolicy => "voc_reader_coordinate_policy",
            Self::VocReaderDepthHandling => "voc_reader_depth_handling",
            Self::VocWriterFileLayout => "voc_writer_file_layout",
            Self::VocWriterNoImageCopy => "voc_writer_no_image_copy",
            Self::VocWriterBoolNormalization => "voc_writer_bool_normalization",
            Self::LabelStudioRotationDropped => "label_studio_rotation_dropped",
            Self::LabelStudioReaderIdAssignment => "label_studio_reader_id_assignment",
            Self::LabelStudioReaderImageRefPolicy => "label_studio_reader_image_ref_policy",
            Self::LabelStudioWriterFromToDefaults => "label_studio_writer_from_to_defaults",
            Self::LabelboxReaderIdAssignment => "labelbox_reader_id_assignment",
            Self::LabelboxReaderImageMetadata => "labelbox_reader_image_metadata",
            Self::LabelboxPolygonEnvelopeApplied => "labelbox_polygon_envelope_applied",
            Self::LabelboxUnsupportedObjectsSkipped => "labelbox_unsupported_objects_skipped",
            Self::LabelboxWriterFormatPolicy => "labelbox_writer_format_policy",
            Self::LabelboxWriterRectanglePolicy => "labelbox_writer_rectangle_policy",
            Self::LabelboxWriterNoImageCopy => "labelbox_writer_no_image_copy",
            Self::ScaleAiReaderIdAssignment => "scale_ai_reader_id_assignment",
            Self::ScaleAiReaderImageMetadata => "scale_ai_reader_image_metadata",
            Self::ScaleAiGeometryEnvelopeApplied => "scale_ai_geometry_envelope_applied",
            Self::ScaleAiWriterDeterministicOrder => "scale_ai_writer_deterministic_order",
            Self::ScaleAiWriterRectanglePolicy => "scale_ai_writer_rectangle_policy",
            Self::ScaleAiWriterNoImageCopy => "scale_ai_writer_no_image_copy",
            Self::UnityPerceptionReaderIdAssignment => "unity_perception_reader_id_assignment",
            Self::UnityPerceptionReaderImageMetadata => "unity_perception_reader_image_metadata",
            Self::UnityPerceptionUnsupportedAnnotationsSkipped => {
                "unity_perception_unsupported_annotations_skipped"
            }
            Self::UnityPerceptionWriterDirectoryLayout => {
                "unity_perception_writer_directory_layout"
            }
            Self::UnityPerceptionWriterRectanglePolicy => {
                "unity_perception_writer_rectangle_policy"
            }
            Self::UnityPerceptionWriterNoImageCopy => "unity_perception_writer_no_image_copy",
            Self::CvatReaderIdAssignment => "cvat_reader_id_assignment",
            Self::CvatReaderAttributePolicy => "cvat_reader_attribute_policy",
            Self::CvatWriterMetaDefaults => "cvat_writer_meta_defaults",
            Self::CvatWriterDeterministicOrder => "cvat_writer_deterministic_order",
            Self::CvatWriterImageIdReassignment => "cvat_writer_image_id_reassignment",
            Self::CvatWriterSourceDefault => "cvat_writer_source_default",
            Self::CvatWriterDropUnusedCategories => "cvat_writer_drop_unused_categories",
            Self::HfReaderCategoryResolution => "hf_reader_category_resolution",
            Self::HfWriterDeterministicOrder => "hf_writer_deterministic_order",
            Self::SagemakerReaderIdAssignment => "sagemaker_reader_id_assignment",
            Self::SagemakerReaderLabelAttributeDetection => {
                "sagemaker_reader_label_attribute_detection"
            }
            Self::SagemakerReaderClassMapResolution => "sagemaker_reader_class_map_resolution",
            Self::SagemakerWriterDeterministicOrder => "sagemaker_writer_deterministic_order",
            Self::SagemakerWriterClassMapPolicy => "sagemaker_writer_class_map_policy",
            Self::SagemakerWriterMetadataDefaults => "sagemaker_writer_metadata_defaults",
            Self::SagemakerWriterNoImageCopy => "sagemaker_writer_no_image_copy",
            Self::LabelmeReaderIdAssignment => "labelme_reader_id_assignment",
            Self::LabelmeReaderPathPolicy => "labelme_reader_path_policy",
            Self::LabelmePolygonEnvelopeApplied => "labelme_polygon_envelope_applied",
            Self::LabelmeWriterFileLayout => "labelme_writer_file_layout",
            Self::LabelmeWriterRectanglePolicy => "labelme_writer_rectangle_policy",
            Self::LabelmeWriterNoImageCopy => "labelme_writer_no_image_copy",
            Self::SuperannotateReaderIdAssignment => "superannotate_reader_id_assignment",
            Self::SuperannotatePolygonEnvelopeApplied => "superannotate_polygon_envelope_applied",
            Self::SuperannotateWriterFileLayout => "superannotate_writer_file_layout",
            Self::SuperannotateWriterRectanglePolicy => "superannotate_writer_rectangle_policy",
            Self::SuperannotateWriterNoImageCopy => "superannotate_writer_no_image_copy",
            Self::SuperviselyReaderIdAssignment => "supervisely_reader_id_assignment",
            Self::SuperviselyPolygonEnvelopeApplied => "supervisely_polygon_envelope_applied",
            Self::SuperviselyWriterProjectLayout => "supervisely_writer_project_layout",
            Self::SuperviselyWriterRectanglePolicy => "supervisely_writer_rectangle_policy",
            Self::SuperviselyWriterNoImageCopy => "supervisely_writer_no_image_copy",
            Self::CityscapesReaderIdAssignment => "cityscapes_reader_id_assignment",
            Self::CityscapesPolygonEnvelopeApplied => "cityscapes_polygon_envelope_applied",
            Self::CityscapesSkippedLabels => "cityscapes_skipped_labels",
            Self::CityscapesWriterGtFineLayout => "cityscapes_writer_gt_fine_layout",
            Self::CityscapesWriterRectanglePolygonPolicy => {
                "cityscapes_writer_rectangle_polygon_policy"
            }
            Self::CityscapesWriterNoImageCopy => "cityscapes_writer_no_image_copy",
            Self::MarmotReaderIdAssignment => "marmot_reader_id_assignment",
            Self::MarmotReaderHexCoordinateTransform => "marmot_reader_hex_coordinate_transform",
            Self::MarmotReaderCompanionImageRequired => "marmot_reader_companion_image_required",
            Self::MarmotWriterMinimalXml => "marmot_writer_minimal_xml",
            Self::MarmotWriterNoImageCopy => "marmot_writer_no_image_copy",
            Self::CreatemlReaderIdAssignment => "createml_reader_id_assignment",
            Self::CreatemlReaderImageResolution => "createml_reader_image_resolution",
            Self::CreatemlWriterDeterministicOrder => "createml_writer_deterministic_order",
            Self::CreatemlWriterCoordinateMapping => "createml_writer_coordinate_mapping",
            Self::CreatemlWriterNoImageCopy => "createml_writer_no_image_copy",
            Self::KittiReaderIdAssignment => "kitti_reader_id_assignment",
            Self::KittiReaderFieldMapping => "kitti_reader_field_mapping",
            Self::KittiReaderImageResolution => "kitti_reader_image_resolution",
            Self::KittiWriterFileLayout => "kitti_writer_file_layout",
            Self::KittiWriterDefaultFieldValues => "kitti_writer_default_field_values",
            Self::KittiWriterDeterministicOrder => "kitti_writer_deterministic_order",
            Self::KittiWriterNoImageCopy => "kitti_writer_no_image_copy",
            Self::ViaReaderIdAssignment => "via_reader_id_assignment",
            Self::ViaReaderLabelResolution => "via_reader_label_resolution",
            Self::ViaReaderImageResolution => "via_reader_image_resolution",
            Self::ViaWriterDeterministicOrder => "via_writer_deterministic_order",
            Self::ViaWriterLabelAttributeKey => "via_writer_label_attribute_key",
            Self::ViaWriterNoImageCopy => "via_writer_no_image_copy",
            Self::VottCsvReaderIdAssignment => "vott_csv_reader_id_assignment",
            Self::VottCsvReaderImageResolution => "vott_csv_reader_image_resolution",
            Self::VottCsvWriterRowOrder => "vott_csv_writer_row_order",
            Self::VottCsvWriterNoImageCopy => "vott_csv_writer_no_image_copy",
            Self::VottJsonReaderIdAssignment => "vott_json_reader_id_assignment",
            Self::VottJsonPolygonEnvelopeApplied => "vott_json_polygon_envelope_applied",
            Self::VottJsonWriterDeterministicOrder => "vott_json_writer_deterministic_order",
            Self::VottJsonWriterRectanglePolicy => "vott_json_writer_rectangle_policy",
            Self::VottJsonWriterNoImageCopy => "vott_json_writer_no_image_copy",
            Self::CloudAnnotationsReaderIdAssignment => "cloud_annotations_reader_id_assignment",
            Self::CloudAnnotationsReaderImageResolution => {
                "cloud_annotations_reader_image_resolution"
            }
            Self::CloudAnnotationsWriterDeterministicOrder => {
                "cloud_annotations_writer_deterministic_order"
            }
            Self::CloudAnnotationsWriterNormalizedCoordinates => {
                "cloud_annotations_writer_normalized_coordinates"
            }
            Self::CloudAnnotationsWriterNoImageCopy => "cloud_annotations_writer_no_image_copy",
            Self::RetinanetReaderIdAssignment => "retinanet_reader_id_assignment",
            Self::RetinanetReaderImageResolution => "retinanet_reader_image_resolution",
            Self::RetinanetReaderEmptyRowHandling => "retinanet_reader_empty_row_handling",
            Self::RetinanetWriterDeterministicOrder => "retinanet_writer_deterministic_order",
            Self::RetinanetWriterEmptyRows => "retinanet_writer_empty_rows",
            Self::RetinanetWriterNoImageCopy => "retinanet_writer_no_image_copy",
            Self::OpenimagesReaderIdAssignment => "openimages_reader_id_assignment",
            Self::OpenimagesReaderImageResolution => "openimages_reader_image_resolution",
            Self::OpenimagesWriterDeterministicOrder => "openimages_writer_deterministic_order",
            Self::DatumaroReaderIdAssignment => "datumaro_reader_id_assignment",
            Self::DatumaroWriterDeterministicOrder => "datumaro_writer_deterministic_order",
            Self::WiderFaceReaderIdAssignment => "wider_face_reader_id_assignment",
            Self::WiderFaceWriterFileLayout => "wider_face_writer_file_layout",
            Self::Oidv4ReaderIdAssignment => "oidv4_reader_id_assignment",
            Self::Oidv4WriterFileLayout => "oidv4_writer_file_layout",
            Self::Bdd100kReaderIdAssignment => "bdd100k_reader_id_assignment",
            Self::Bdd100kWriterDeterministicOrder => "bdd100k_writer_deterministic_order",
            Self::V7DarwinReaderIdAssignment => "v7_darwin_reader_id_assignment",
            Self::V7DarwinWriterDeterministicOrder => "v7_darwin_writer_deterministic_order",
            Self::EdgeImpulseReaderIdAssignment => "edge_impulse_reader_id_assignment",
            Self::EdgeImpulseWriterDeterministicOrder => "edge_impulse_writer_deterministic_order",
            Self::OpenlabelReaderIdAssignment => "openlabel_reader_id_assignment",
            Self::OpenlabelWriterFrameLayout => "openlabel_writer_frame_layout",
            Self::ViaCsvReaderIdAssignment => "via_csv_reader_id_assignment",
            Self::ViaCsvWriterDeterministicOrder => "via_csv_writer_deterministic_order",
            Self::KaggleWheatReaderIdAssignment => "kaggle_wheat_reader_id_assignment",
            Self::KaggleWheatWriterDeterministicOrder => "kaggle_wheat_writer_deterministic_order",
            Self::CollapseMultipleCategoriesToSingleClass => {
                "collapse_multiple_categories_to_single_class"
            }
            Self::AutomlVisionReaderIdAssignment => "automl_vision_reader_id_assignment",
            Self::AutomlVisionReaderImageResolution => "automl_vision_reader_image_resolution",
            Self::AutomlVisionWriterDeterministicOrder => {
                "automl_vision_writer_deterministic_order"
            }
            Self::UdacityReaderIdAssignment => "udacity_reader_id_assignment",
            Self::UdacityWriterRowOrder => "udacity_writer_row_order",
        }
    }
}

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

    #[test]
    fn empty_report_is_not_lossy() {
        let report = ConversionReport::new("coco", "ir-json");
        assert!(!report.is_lossy());
        assert_eq!(report.warning_count(), 0);
        assert_eq!(report.info_count(), 0);
    }

    #[test]
    fn warning_makes_report_lossy() {
        let mut report = ConversionReport::new("ir-json", "tfod");
        report.add(ConversionIssue::warning(
            ConversionIssueCode::DropDatasetInfo,
            "dataset info will be dropped",
        ));
        assert!(report.is_lossy());
        assert_eq!(report.warning_count(), 1);
    }

    #[test]
    fn info_does_not_make_report_lossy() {
        let mut report = ConversionReport::new("tfod", "coco");
        report.add(ConversionIssue::info(
            ConversionIssueCode::TfodReaderIdAssignment,
            "IDs assigned by lexicographic order",
        ));
        assert!(!report.is_lossy());
        assert_eq!(report.info_count(), 1);
    }

    #[test]
    fn report_serializes_to_json() {
        let mut report = ConversionReport::new("coco", "tfod");
        report.input = ConversionCounts {
            images: 10,
            categories: 3,
            annotations: 50,
        };
        report.add(ConversionIssue::warning(
            ConversionIssueCode::DropLicenses,
            "2 license(s) will be dropped",
        ));

        let json = serde_json::to_string(&report).unwrap();
        assert!(json.contains("\"from\":\"coco\""));
        assert!(json.contains("\"severity\":\"warning\""));
        assert!(json.contains("\"code\":\"drop_licenses\""));
    }

    #[test]
    fn as_str_matches_serde_json_for_all_codes() {
        // Verify that as_str() produces the same string as serde serialization
        // for EVERY code in ALL — catches as_str()/serde drift.
        for code in ConversionIssueCode::ALL {
            let json = serde_json::to_value(code).unwrap();
            assert_eq!(
                json.as_str().unwrap(),
                code.as_str(),
                "as_str() and serde disagree for {:?}",
                code
            );
        }
    }

    #[test]
    fn all_codes_have_unique_str() {
        let mut seen = std::collections::HashSet::new();
        for code in ConversionIssueCode::ALL {
            assert!(
                seen.insert(code.as_str()),
                "duplicate as_str() value: {}",
                code.as_str()
            );
        }
    }

    #[test]
    fn all_codes_documented_in_conversion_md() {
        let docs =
            std::fs::read_to_string("docs/conversion.md").expect("docs/conversion.md should exist");
        let mut missing = Vec::new();
        for code in ConversionIssueCode::ALL {
            if !docs.contains(code.as_str()) {
                missing.push(code.as_str());
            }
        }
        assert!(
            missing.is_empty(),
            "docs/conversion.md is missing these issue codes: {:?}",
            missing
        );
    }

    #[test]
    fn text_display_includes_stable_codes() {
        let mut report = ConversionReport::new("coco", "tfod");
        report.input = ConversionCounts {
            images: 5,
            categories: 2,
            annotations: 10,
        };
        report.output = report.input.clone();
        report.add(ConversionIssue::warning(
            ConversionIssueCode::DropDatasetInfo,
            "dataset info will be dropped",
        ));
        report.add(ConversionIssue::info(
            ConversionIssueCode::TfodWriterRowOrder,
            "rows ordered by annotation ID",
        ));

        let text = format!("{}", report);
        assert!(
            text.contains("[drop_dataset_info]"),
            "text should contain warning code"
        );
        assert!(
            text.contains("[tfod_writer_row_order]"),
            "text should contain info code"
        );
    }
}