use num_dual::linalg::LinAlgError;
use std::io;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum FeosError {
#[error("{0}")]
Error(String),
#[error("`{0}` did not converge within the maximum number of iterations.")]
NotConverged(String),
#[error("`{0}` encountered illegal values during the iteration.")]
IterationFailed(String),
#[error("Iteration resulted in trivial solution.")]
TrivialSolution,
#[error(
"Equation of state is initialized for {0} components while the input specifies {1} components."
)]
IncompatibleComponents(usize, usize),
#[error("Invalid state in {0}: {1} = {2}.")]
InvalidState(String, String, f64),
#[error("Undetermined state: {0}.")]
UndeterminedState(String),
#[error("System is supercritical.")]
SuperCritical,
#[error("No phase split according to stability analysis.")]
NoPhaseSplit,
#[error("Wrong input units. Expected {0}, got {1}")]
WrongUnits(String, String),
#[error(transparent)]
FileIO(#[from] io::Error),
#[error(transparent)]
Serde(#[from] serde_json::Error),
#[error("The following component(s) were not found: {0}")]
ComponentsNotFound(String),
#[error(
"The identifier '{0}' is not known. ['cas', 'name', 'iupacname', 'smiles', inchi', 'formula']"
)]
IdentifierNotFound(String),
#[error("Information missing.")]
InsufficientInformation,
#[error("Incompatible parameters: {0}")]
IncompatibleParameters(String),
#[error("Missing parameters: {0}")]
MissingParameters(String),
#[error(transparent)]
LinAlgError(#[from] LinAlgError),
#[cfg(feature = "rayon")]
#[error(transparent)]
RayonError(#[from] rayon::ThreadPoolBuildError),
#[cfg(feature = "ndarray")]
#[error(transparent)]
ShapeError(#[from] ndarray::ShapeError),
}
pub type FeosResult<T> = Result<T, FeosError>;