use crate::EntityId;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, ParseError>;
#[derive(Error, Debug)]
pub enum ParseError {
#[error("Invalid IFC format: {0}")]
InvalidFormat(String),
#[error("Invalid header: {0}")]
InvalidHeader(String),
#[error("Failed to parse entity {0}: {1}")]
EntityParse(EntityId, String),
#[error("Entity {0} not found")]
EntityNotFound(EntityId),
#[error("Invalid entity reference at {entity}: attribute {attribute}")]
InvalidReference { entity: EntityId, attribute: usize },
#[error(
"Type mismatch at entity {entity} attribute {attribute}: expected {expected}, got {actual}"
)]
TypeMismatch {
entity: EntityId,
attribute: usize,
expected: String,
actual: String,
},
#[error("Missing required attribute {attribute} on entity {entity}")]
MissingAttribute { entity: EntityId, attribute: usize },
#[error("Unsupported schema version: {0}")]
UnsupportedSchema(String),
#[error("Geometry error for entity {entity}: {message}")]
Geometry { entity: EntityId, message: String },
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("{0}")]
Other(String),
}
impl ParseError {
pub fn format(msg: impl Into<String>) -> Self {
ParseError::InvalidFormat(msg.into())
}
pub fn entity_parse(id: EntityId, msg: impl Into<String>) -> Self {
ParseError::EntityParse(id, msg.into())
}
pub fn geometry(entity: EntityId, msg: impl Into<String>) -> Self {
ParseError::Geometry {
entity,
message: msg.into(),
}
}
pub fn other(msg: impl Into<String>) -> Self {
ParseError::Other(msg.into())
}
}