use thiserror::Error;
#[derive(Debug, Error)]
pub enum TranslationError {
#[error("unsupported message type: {0}")]
UnsupportedMessageType(String),
#[error("missing required field: {field} for {context}")]
MissingField { field: String, context: String },
#[error("invalid field value: {field}: {detail}")]
InvalidFieldValue { field: String, detail: String },
#[error("MT parse error: {0}")]
MtParse(#[from] crate::mt::MtError),
#[error("MX parse error: {0}")]
MxParse(#[from] mx20022_parse::ParseError),
#[error("builder error: {0}")]
Builder(#[from] mx20022_model::common::BuilderError),
}
#[derive(Debug, Clone, PartialEq)]
pub struct TranslationWarning {
pub field: String,
pub message: String,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct TranslationWarnings {
pub warnings: Vec<TranslationWarning>,
}
impl TranslationWarnings {
pub fn add(&mut self, field: impl Into<String>, message: impl Into<String>) {
self.warnings.push(TranslationWarning {
field: field.into(),
message: message.into(),
});
}
pub fn is_empty(&self) -> bool {
self.warnings.is_empty()
}
}
#[derive(Debug)]
pub struct TranslationResult<T: std::fmt::Debug> {
pub message: T,
pub warnings: TranslationWarnings,
}