use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum BuyerFinancing {
Assumed,
Cash,
Contract,
Conventional,
FHA,
FHA203b,
FHA203k,
Other,
Private,
SellerFinancing,
TrustDeed,
USDA,
VA,
OpenEnumeration(String),
}
impl crate::ResoEnumeration for BuyerFinancing {
fn from_str(s: &str) -> BuyerFinancing {
match s {
"Assumed" => BuyerFinancing::Assumed,
"Cash" => BuyerFinancing::Cash,
"Contract" => BuyerFinancing::Contract,
"Conventional" => BuyerFinancing::Conventional,
"FHA" => BuyerFinancing::FHA,
"FHA 203(b)" => BuyerFinancing::FHA203b,
"FHA 203(k)" => BuyerFinancing::FHA203k,
"Other" => BuyerFinancing::Other,
"Private" => BuyerFinancing::Private,
"Seller Financing" => BuyerFinancing::SellerFinancing,
"Trust Deed" => BuyerFinancing::TrustDeed,
"USDA" => BuyerFinancing::USDA,
"VA" => BuyerFinancing::VA,
_ => BuyerFinancing::OpenEnumeration(s.into()),
}
}
fn from_string(s: String) -> BuyerFinancing {
match s.as_ref() {
"Assumed" => BuyerFinancing::Assumed,
"Cash" => BuyerFinancing::Cash,
"Contract" => BuyerFinancing::Contract,
"Conventional" => BuyerFinancing::Conventional,
"FHA" => BuyerFinancing::FHA,
"FHA 203(b)" => BuyerFinancing::FHA203b,
"FHA 203(k)" => BuyerFinancing::FHA203k,
"Other" => BuyerFinancing::Other,
"Private" => BuyerFinancing::Private,
"Seller Financing" => BuyerFinancing::SellerFinancing,
"Trust Deed" => BuyerFinancing::TrustDeed,
"USDA" => BuyerFinancing::USDA,
"VA" => BuyerFinancing::VA,
_ => BuyerFinancing::OpenEnumeration(s),
}
}
fn to_str(&self) -> &str {
match self {
BuyerFinancing::Assumed => "Assumed",
BuyerFinancing::Cash => "Cash",
BuyerFinancing::Contract => "Contract",
BuyerFinancing::Conventional => "Conventional",
BuyerFinancing::FHA => "FHA",
BuyerFinancing::FHA203b => "FHA 203(b)",
BuyerFinancing::FHA203k => "FHA 203(k)",
BuyerFinancing::Other => "Other",
BuyerFinancing::Private => "Private",
BuyerFinancing::SellerFinancing => "Seller Financing",
BuyerFinancing::TrustDeed => "Trust Deed",
BuyerFinancing::USDA => "USDA",
BuyerFinancing::VA => "VA",
BuyerFinancing::OpenEnumeration(ref s) => s,
}
}
fn into_string(self) -> String {
match self {
BuyerFinancing::Assumed => "Assumed".into(),
BuyerFinancing::Cash => "Cash".into(),
BuyerFinancing::Contract => "Contract".into(),
BuyerFinancing::Conventional => "Conventional".into(),
BuyerFinancing::FHA => "FHA".into(),
BuyerFinancing::FHA203b => "FHA 203(b)".into(),
BuyerFinancing::FHA203k => "FHA 203(k)".into(),
BuyerFinancing::Other => "Other".into(),
BuyerFinancing::Private => "Private".into(),
BuyerFinancing::SellerFinancing => "Seller Financing".into(),
BuyerFinancing::TrustDeed => "Trust Deed".into(),
BuyerFinancing::USDA => "USDA".into(),
BuyerFinancing::VA => "VA".into(),
BuyerFinancing::OpenEnumeration(s) => s,
}
}
fn fallback_value(&self) -> Option<&str> {
match self {
BuyerFinancing::OpenEnumeration(ref s) => Some(s),
_ => None,
}
}
}
impl From<String> for BuyerFinancing {
fn from(s: String) -> BuyerFinancing {
match s.as_ref() {
"Assumed" => BuyerFinancing::Assumed,
"Cash" => BuyerFinancing::Cash,
"Contract" => BuyerFinancing::Contract,
"Conventional" => BuyerFinancing::Conventional,
"FHA" => BuyerFinancing::FHA,
"FHA 203(b)" => BuyerFinancing::FHA203b,
"FHA 203(k)" => BuyerFinancing::FHA203k,
"Other" => BuyerFinancing::Other,
"Private" => BuyerFinancing::Private,
"Seller Financing" => BuyerFinancing::SellerFinancing,
"Trust Deed" => BuyerFinancing::TrustDeed,
"USDA" => BuyerFinancing::USDA,
"VA" => BuyerFinancing::VA,
_ => BuyerFinancing::OpenEnumeration(s),
}
}
}
impl From<&str> for BuyerFinancing {
fn from(s: &str) -> BuyerFinancing {
match s {
"Assumed" => BuyerFinancing::Assumed,
"Cash" => BuyerFinancing::Cash,
"Contract" => BuyerFinancing::Contract,
"Conventional" => BuyerFinancing::Conventional,
"FHA" => BuyerFinancing::FHA,
"FHA 203(b)" => BuyerFinancing::FHA203b,
"FHA 203(k)" => BuyerFinancing::FHA203k,
"Other" => BuyerFinancing::Other,
"Private" => BuyerFinancing::Private,
"Seller Financing" => BuyerFinancing::SellerFinancing,
"Trust Deed" => BuyerFinancing::TrustDeed,
"USDA" => BuyerFinancing::USDA,
"VA" => BuyerFinancing::VA,
_ => BuyerFinancing::OpenEnumeration(s.into()),
}
}
}
impl<'a> From<&'a BuyerFinancing> for &'a str {
fn from(s: &'a BuyerFinancing) -> &'a str {
match s {
BuyerFinancing::Assumed => "Assumed",
BuyerFinancing::Cash => "Cash",
BuyerFinancing::Contract => "Contract",
BuyerFinancing::Conventional => "Conventional",
BuyerFinancing::FHA => "FHA",
BuyerFinancing::FHA203b => "FHA 203(b)",
BuyerFinancing::FHA203k => "FHA 203(k)",
BuyerFinancing::Other => "Other",
BuyerFinancing::Private => "Private",
BuyerFinancing::SellerFinancing => "Seller Financing",
BuyerFinancing::TrustDeed => "Trust Deed",
BuyerFinancing::USDA => "USDA",
BuyerFinancing::VA => "VA",
BuyerFinancing::OpenEnumeration(s) => s,
}
}
}
impl Serialize for BuyerFinancing {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.into())
}
}
impl<'de> Deserialize<'de> for BuyerFinancing {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(From::from(s))
}
}