use serde::{ Deserialize, Serialize };
use crate::transaction_type_parse_error::TransactionTypeParseError;
use std::str::FromStr;
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
#[serde(rename_all = "lowercase")]
pub enum TransactionType {
Deposit,
Withdrawal
}
impl FromStr for TransactionType {
type Err = TransactionTypeParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"deposit" => Ok(Self::Deposit),
"withdrawal" => Ok(Self::Withdrawal),
_ => Err(TransactionTypeParseError::InvalidType(s.to_lowercase()))
}
}
}