use core::time::Duration;

use bone_types::{ParameterIndex, SketchItemId, SolverResidual};

#[derive(Debug, Clone, PartialEq, thiserror::Error)]
pub enum SolverError {
    #[error("no solution found (last residual = {last})")]
    NoSolutionFound { last: SolverResidual },
    #[error("sketch is over-defined ({} conflicting items)", conflicts.len())]
    OverDefined { conflicts: Vec<SketchItemId> },
    #[error("invalid solution found: jacobian singular at parameter {at}")]
    InvalidSolutionFound { at: ParameterIndex },
    #[error("solver budget exhausted after {elapsed:?}")]
    Budget { elapsed: Duration },
}

pub type Result<T, E = SolverError> = core::result::Result<T, E>;
