use serde_json::Value;
use crate::license::CalculatorLicense;
use crate::response::CalculationResponse;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CalcError {
InvalidInput(String),
}
impl std::fmt::Display for CalcError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CalcError::InvalidInput(msg) => write!(f, "invalid input: {msg}"),
}
}
}
impl std::error::Error for CalcError {}
pub trait Calculator {
fn name(&self) -> &'static str;
fn title(&self) -> &'static str;
fn description(&self) -> &'static str;
fn reference(&self) -> &'static str;
fn license(&self) -> CalculatorLicense;
fn input_schema(&self) -> Value;
fn calculate(&self, input: &Value) -> Result<CalculationResponse, CalcError>;
fn input_template(&self) -> Value {
crate::template::template_from_schema(&self.input_schema())
}
fn tags(&self) -> &'static [&'static str] {
crate::tags::for_name(self.name())
}
}