Skip to main content

automapper_validation/validator/
codes.rs

1//! Standard error codes for validation issues.
2//!
3//! Error codes follow a prefix convention:
4//! - `STR0xx`: Structure validation
5//! - `FMT0xx`: Format validation
6//! - `COD0xx`: Code value validation
7//! - `AHB0xx`: AHB condition rule validation
8
9/// Standard error codes for validation issues.
10pub struct ErrorCodes;
11
12impl ErrorCodes {
13    // --- Structure validation (STR001-STR099) ---
14
15    /// A mandatory segment is missing.
16    pub const MISSING_MANDATORY_SEGMENT: &'static str = "STR001";
17
18    /// Segment repetitions exceed the MIG MaxRep count.
19    pub const MAX_REPETITIONS_EXCEEDED: &'static str = "STR002";
20
21    /// Unexpected segment found (not defined in MIG for this message type).
22    pub const UNEXPECTED_SEGMENT: &'static str = "STR003";
23
24    /// Segments are in wrong order according to the MIG.
25    pub const WRONG_SEGMENT_ORDER: &'static str = "STR004";
26
27    /// A mandatory segment group is missing.
28    pub const MISSING_MANDATORY_GROUP: &'static str = "STR005";
29
30    /// Segment group repetitions exceed MaxRep count.
31    pub const GROUP_MAX_REP_EXCEEDED: &'static str = "STR006";
32
33    // --- Format validation (FMT001-FMT099) ---
34
35    /// Value exceeds maximum allowed length.
36    pub const VALUE_TOO_LONG: &'static str = "FMT001";
37
38    /// Value does not match required numeric format.
39    pub const INVALID_NUMERIC_FORMAT: &'static str = "FMT002";
40
41    /// Value does not match required alphanumeric format.
42    pub const INVALID_ALPHANUMERIC_FORMAT: &'static str = "FMT003";
43
44    /// Invalid date/time format.
45    pub const INVALID_DATE_FORMAT: &'static str = "FMT004";
46
47    /// Value is shorter than minimum required length.
48    pub const VALUE_TOO_SHORT: &'static str = "FMT005";
49
50    /// A required element is empty.
51    pub const REQUIRED_ELEMENT_EMPTY: &'static str = "FMT006";
52
53    // --- Code validation (COD001-COD099) ---
54
55    /// Code value is not in the allowed code list for this element.
56    pub const INVALID_CODE_VALUE: &'static str = "COD001";
57
58    /// Code value is not allowed for this specific Pruefidentifikator.
59    pub const CODE_NOT_ALLOWED_FOR_PID: &'static str = "COD002";
60
61    // --- AHB validation (AHB001-AHB999) ---
62
63    /// A field required by the AHB for this PID is missing.
64    pub const MISSING_REQUIRED_FIELD: &'static str = "AHB001";
65
66    /// A field is present but not allowed by the AHB for this PID.
67    pub const FIELD_NOT_ALLOWED_FOR_PID: &'static str = "AHB002";
68
69    /// A conditional AHB rule is violated.
70    pub const CONDITIONAL_RULE_VIOLATION: &'static str = "AHB003";
71
72    /// The Pruefidentifikator is unknown / not supported.
73    pub const UNKNOWN_PRUEFIDENTIFIKATOR: &'static str = "AHB004";
74
75    /// A condition expression could not be fully evaluated (Unknown result).
76    pub const CONDITION_UNKNOWN: &'static str = "AHB005";
77
78    /// Package cardinality constraint violated: count of present codes outside [min..max].
79    pub const PACKAGE_CARDINALITY_VIOLATION: &'static str = "AHB006";
80}
81
82#[cfg(test)]
83mod tests {
84    use super::*;
85
86    #[test]
87    fn test_error_code_prefixes() {
88        assert!(ErrorCodes::MISSING_MANDATORY_SEGMENT.starts_with("STR"));
89        assert!(ErrorCodes::VALUE_TOO_LONG.starts_with("FMT"));
90        assert!(ErrorCodes::INVALID_CODE_VALUE.starts_with("COD"));
91        assert!(ErrorCodes::MISSING_REQUIRED_FIELD.starts_with("AHB"));
92    }
93
94    #[test]
95    fn test_all_codes_are_unique() {
96        let codes = [
97            ErrorCodes::MISSING_MANDATORY_SEGMENT,
98            ErrorCodes::MAX_REPETITIONS_EXCEEDED,
99            ErrorCodes::UNEXPECTED_SEGMENT,
100            ErrorCodes::WRONG_SEGMENT_ORDER,
101            ErrorCodes::MISSING_MANDATORY_GROUP,
102            ErrorCodes::GROUP_MAX_REP_EXCEEDED,
103            ErrorCodes::VALUE_TOO_LONG,
104            ErrorCodes::INVALID_NUMERIC_FORMAT,
105            ErrorCodes::INVALID_ALPHANUMERIC_FORMAT,
106            ErrorCodes::INVALID_DATE_FORMAT,
107            ErrorCodes::VALUE_TOO_SHORT,
108            ErrorCodes::REQUIRED_ELEMENT_EMPTY,
109            ErrorCodes::INVALID_CODE_VALUE,
110            ErrorCodes::CODE_NOT_ALLOWED_FOR_PID,
111            ErrorCodes::MISSING_REQUIRED_FIELD,
112            ErrorCodes::FIELD_NOT_ALLOWED_FOR_PID,
113            ErrorCodes::CONDITIONAL_RULE_VIOLATION,
114            ErrorCodes::UNKNOWN_PRUEFIDENTIFIKATOR,
115            ErrorCodes::CONDITION_UNKNOWN,
116            ErrorCodes::PACKAGE_CARDINALITY_VIOLATION,
117        ];
118
119        let unique: std::collections::HashSet<&str> = codes.iter().copied().collect();
120        assert_eq!(codes.len(), unique.len(), "Duplicate error codes found");
121    }
122}