scirs2_core/validation/data/
config.rs

1//! Configuration types for data validation
2//!
3//! This module provides configuration structures and types for controlling
4//! the behavior of the data validation system.
5
6use std::collections::HashMap;
7
8use serde::{Deserialize, Serialize};
9
10/// Data validation configuration
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct ValidationConfig {
13    /// Enable strict mode (fail fast on first error)
14    pub strict_mode: bool,
15    /// Maximum validation depth for nested structures
16    pub max_depth: usize,
17    /// Enable validation caching
18    pub enable_caching: bool,
19    /// Cache size limit
20    pub cache_size_limit: usize,
21    /// Enable parallel validation for arrays
22    pub enable_parallel_validation: bool,
23    /// Custom validation rules
24    pub custom_rules: HashMap<String, String>,
25    /// Enable detailed error reporting
26    pub detailederrors: bool,
27    /// Performance mode (reduced checks for speed)
28    pub performance_mode: bool,
29}
30
31impl Default for ValidationConfig {
32    fn default() -> Self {
33        Self {
34            strict_mode: false,
35            max_depth: 100,
36            enable_caching: true,
37            cache_size_limit: 1000,
38            enable_parallel_validation: false, // Can be expensive
39            custom_rules: HashMap::new(),
40            detailederrors: true,
41            performance_mode: false,
42        }
43    }
44}
45
46/// Error severity levels
47#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
48pub enum ErrorSeverity {
49    /// Warning - data may still be usable
50    Warning,
51    /// Error - data should not be used
52    Error,
53    /// Critical - data is corrupted or dangerous
54    Critical,
55}
56
57/// Types of data quality issues
58#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
59pub enum QualityIssueType {
60    /// Missing or null values
61    MissingData,
62    /// Invalid numeric values (NaN, infinity)
63    InvalidNumeric,
64    /// Out-of-range values
65    OutOfRange,
66    /// Inconsistent format
67    FormatInconsistency,
68    /// Statistical outliers
69    Outlier,
70    /// Duplicate entries
71    Duplicate,
72    /// Type mismatch
73    TypeMismatch,
74    /// Constraint violation
75    ConstraintViolation,
76    /// Performance issue
77    Performance,
78}
79
80/// Enhanced validation error type
81#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
82pub enum ValidationErrorType {
83    /// Required field missing
84    MissingRequiredField,
85    /// Type mismatch
86    TypeMismatch,
87    /// Constraint violation
88    ConstraintViolation,
89    /// Invalid format
90    InvalidFormat,
91    /// Out of range value
92    OutOfRange,
93    /// Invalid array size
94    InvalidArraySize,
95    /// Duplicate values where unique required
96    DuplicateValues,
97    /// Data integrity failure
98    IntegrityFailure,
99    /// Custom validation rule failure
100    CustomRuleFailure,
101    /// Schema validation error
102    SchemaError,
103    /// Shape validation error
104    ShapeError,
105    /// Numeric quality error (NaN, infinity)
106    InvalidNumeric,
107    /// Statistical constraint violation
108    StatisticalViolation,
109    /// Performance issue
110    Performance,
111    /// Data integrity error
112    IntegrityError,
113    /// Type conversion error
114    TypeConversion,
115}
116
117#[cfg(test)]
118mod tests {
119    use super::*;
120
121    #[test]
122    fn test_default_config() {
123        let config = ValidationConfig::default();
124        assert!(!config.strict_mode);
125        assert_eq!(config.max_depth, 100);
126        assert!(config.enable_caching);
127        assert_eq!(config.cache_size_limit, 1000);
128        assert!(!config.enable_parallel_validation);
129        assert!(config.detailederrors);
130        assert!(!config.performance_mode);
131    }
132
133    #[test]
134    fn testerror_severity_ordering() {
135        assert!(ErrorSeverity::Warning < ErrorSeverity::Error);
136        assert!(ErrorSeverity::Error < ErrorSeverity::Critical);
137    }
138
139    #[test]
140    fn test_quality_issue_types() {
141        let issue_type = QualityIssueType::MissingData;
142        assert_eq!(issue_type, QualityIssueType::MissingData);
143    }
144
145    #[test]
146    fn test_validationerrortypes() {
147        let errortype = ValidationErrorType::TypeMismatch;
148        assert_eq!(errortype, ValidationErrorType::TypeMismatch);
149    }
150}