use std::error::Error;
use std::sync::Arc;
#[derive(Debug, Clone, thiserror::Error)]
pub enum ServicesValidationError {
#[error("{0}")]
Required(String),
#[error("{0}")]
InvalidField(String),
#[error("{context}: {source}")]
InvalidFieldCause {
context: String,
#[source]
source: Arc<dyn Error + Send + Sync>,
},
#[error("{0}")]
PortConflict(String),
#[error("{0}")]
UnknownReference(String),
#[error("{0}")]
CircularDependency(String),
#[error("{0}")]
BusinessRule(String),
}
impl ServicesValidationError {
#[must_use]
pub fn required(msg: impl Into<String>) -> Self {
Self::Required(msg.into())
}
#[must_use]
pub fn invalid_field(msg: impl Into<String>) -> Self {
Self::InvalidField(msg.into())
}
#[must_use]
pub fn invalid_field_cause(
context: impl Into<String>,
source: impl Error + Send + Sync + 'static,
) -> Self {
Self::InvalidFieldCause {
context: context.into(),
source: Arc::new(source),
}
}
#[must_use]
pub fn port_conflict(msg: impl Into<String>) -> Self {
Self::PortConflict(msg.into())
}
#[must_use]
pub fn unknown_reference(msg: impl Into<String>) -> Self {
Self::UnknownReference(msg.into())
}
#[must_use]
pub fn circular_dependency(msg: impl Into<String>) -> Self {
Self::CircularDependency(msg.into())
}
#[must_use]
pub fn business_rule(msg: impl Into<String>) -> Self {
Self::BusinessRule(msg.into())
}
}