use thiserror::Error;
#[derive(Error, Debug)]
pub enum SimError {
#[error("Configuration error: {0}")]
Config(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("Entity not found: {entity_type} with id {id}")]
NotFound { entity_type: &'static str, id: u32 },
#[error("Invalid state transition: {0}")]
InvalidState(String),
#[error("Capacity exceeded: {0}")]
CapacityExceeded(String),
#[error("Inventory error: {0}")]
Inventory(String),
#[error("Routing error: no path from {from} to {to}")]
NoPath { from: u32, to: u32 },
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Serialization error: {0}")]
Serialization(String),
}
impl SimError {
pub fn robot_not_found(id: u32) -> Self {
Self::NotFound {
entity_type: "Robot",
id,
}
}
pub fn node_not_found(id: u32) -> Self {
Self::NotFound {
entity_type: "Node",
id,
}
}
pub fn edge_not_found(id: u32) -> Self {
Self::NotFound {
entity_type: "Edge",
id,
}
}
pub fn station_not_found(id: u32) -> Self {
Self::NotFound {
entity_type: "Station",
id,
}
}
pub fn task_not_found(id: u32) -> Self {
Self::NotFound {
entity_type: "Task",
id,
}
}
pub fn order_not_found(id: u32) -> Self {
Self::NotFound {
entity_type: "Order",
id,
}
}
pub fn sku_not_found(id: u32) -> Self {
Self::NotFound {
entity_type: "SKU",
id,
}
}
}
pub type SimResult<T> = Result<T, SimError>;