use serde_json::{Map, Value};
#[derive(Debug, Clone, PartialEq)]
pub struct VerificationResult {
pub success: bool,
pub score: Option<f64>,
pub error_codes: Vec<String>,
pub raw: Map<String, Value>,
}
impl VerificationResult {
pub fn new(success: bool) -> Self {
Self {
success,
score: None,
error_codes: Vec::new(),
raw: Map::new(),
}
}
pub fn failure(code: impl Into<String>) -> Self {
Self {
error_codes: vec![code.into()],
..Self::new(false)
}
}
pub fn passed(&self) -> bool {
self.success
}
pub fn failed(&self) -> bool {
!self.success
}
#[must_use]
pub fn refused(&self, code: &str) -> Self {
let mut error_codes = self.error_codes.clone();
error_codes.push(code.to_owned());
Self {
success: false,
score: self.score,
error_codes,
raw: self.raw.clone(),
}
}
pub fn has_error(&self, code: &str) -> bool {
self.error_codes.iter().any(|candidate| candidate == code)
}
}