use ifc_model::EntityId;
use ifc_schema::SchemaVersion;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum ElementTypeError {
Invalid {
entity: &'static str,
attribute: &'static str,
value: String,
},
MultipleSchemas {
schemas: usize,
},
UnsupportedSchema {
schema: String,
},
EntityNotInSchema {
entity: &'static str,
schema: SchemaVersion,
},
AuthoringNotInSchema {
entity: &'static str,
attribute: &'static str,
schema: SchemaVersion,
},
AuthoringRequired {
entity: &'static str,
attribute: &'static str,
schema: SchemaVersion,
},
MissingEntity {
id: EntityId,
},
}
impl std::fmt::Display for ElementTypeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Invalid {
entity,
attribute,
value,
} => write!(f, "{entity}.{attribute}: {value}"),
Self::MultipleSchemas { schemas } => write!(
f,
"the header declares {schemas} schemas; authoring binds to exactly one"
),
Self::UnsupportedSchema { schema } => {
write!(
f,
"the header declares {schema}, which has no bundled table"
)
}
Self::EntityNotInSchema { entity, schema } => {
write!(f, "{entity} is not an instantiable entity of {schema:?}")
}
Self::AuthoringNotInSchema {
entity,
attribute,
schema,
} => write!(
f,
"cannot author {entity}.{attribute}: not defined by {schema:?}"
),
Self::AuthoringRequired {
entity,
attribute,
schema,
} => write!(f, "cannot author {entity}: {schema:?} requires {attribute}"),
Self::MissingEntity { id } => write!(f, "entity #{} does not exist", id.0),
}
}
}
impl std::error::Error for ElementTypeError {}
pub type ElementTypeResult<T> = Result<T, ElementTypeError>;