use thiserror::Error;
#[derive(Debug, Error)]
pub enum BuilderError {
#[error("Validation error: {message}. Suggestion: {suggestion}")]
ValidationError { message: String, suggestion: String },
#[error("Missing required field: {field}. Call {suggestion} first")]
MissingField { field: String, suggestion: String },
#[error("Invalid entity reference: '{entity}'. Available entities: {available}")]
InvalidEntityRef { entity: String, available: String },
#[error("Constraint violation: {constraint}. Details: {details}")]
ConstraintViolation { constraint: String, details: String },
#[error("OpenSCENARIO error: {0}")]
OpenScenarioError(#[from] crate::error::Error),
}
impl BuilderError {
pub fn validation_error(message: &str) -> Self {
Self::ValidationError {
message: message.to_string(),
suggestion: "Check the documentation for valid values".to_string(),
}
}
pub fn validation_error_with_suggestion(message: &str, suggestion: &str) -> Self {
Self::ValidationError {
message: message.to_string(),
suggestion: suggestion.to_string(),
}
}
pub fn missing_field(field: &str, suggestion: &str) -> Self {
Self::MissingField {
field: field.to_string(),
suggestion: suggestion.to_string(),
}
}
pub fn invalid_entity_ref(entity: &str, available: &[String]) -> Self {
Self::InvalidEntityRef {
entity: entity.to_string(),
available: available.join(", "),
}
}
pub fn constraint_violation(constraint: &str, details: &str) -> Self {
Self::ConstraintViolation {
constraint: constraint.to_string(),
details: details.to_string(),
}
}
}
pub type BuilderResult<T> = Result<T, BuilderError>;