fastskill_core/validation/
result.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct ValidationResult {
8 pub is_valid: bool,
10
11 pub errors: Vec<ValidationError>,
13
14 pub warnings: Vec<ValidationWarning>,
16
17 pub score: f64,
19}
20
21impl ValidationResult {
22 pub fn valid() -> Self {
24 Self {
25 is_valid: true,
26 errors: Vec::new(),
27 warnings: Vec::new(),
28 score: 1.0,
29 }
30 }
31
32 pub fn invalid(error: &str) -> Self {
34 Self {
35 is_valid: false,
36 errors: vec![ValidationError {
37 field: "general".to_string(),
38 message: error.to_string(),
39 severity: ErrorSeverity::Error,
40 }],
41 warnings: Vec::new(),
42 score: 0.0,
43 }
44 }
45
46 pub fn with_error(mut self, field: &str, message: &str, severity: ErrorSeverity) -> Self {
48 self.errors.push(ValidationError {
49 field: field.to_string(),
50 message: message.to_string(),
51 severity,
52 });
53 self.is_valid = false;
54 self.score = 0.0;
55 self
56 }
57
58 pub fn with_warning(mut self, field: &str, message: &str) -> Self {
60 self.warnings.push(ValidationWarning {
61 field: field.to_string(),
62 message: message.to_string(),
63 });
64 self
65 }
66
67 pub(crate) fn calculate_score(&mut self) {
69 let error_penalty = self.errors.len() as f64 * 0.3;
70 let warning_penalty = self.warnings.len() as f64 * 0.1;
71
72 self.score = (1.0 - error_penalty - warning_penalty).max(0.0);
73 }
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78pub struct ValidationError {
79 pub field: String,
81
82 pub message: String,
84
85 pub severity: ErrorSeverity,
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
91pub enum ErrorSeverity {
92 Warning,
94 Error,
96 Critical,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
102pub struct ValidationWarning {
103 pub field: String,
105
106 pub message: String,
108}