use std::fmt::{self, Display, Formatter, Write};
use validators::{Validated, ValidatedWrapper};
use super::{
super::{
parameters::{any::Any, Parameter},
values::{product_id_value::ProductIDValue, Value},
Set,
},
*,
};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct ProductID {
pub any: Option<Set<Any>>,
pub value: ProductIDValue,
}
impl ProductID {
pub fn from_product_id_value(product_id_value: ProductIDValue) -> ProductID {
ProductID {
any: None, value: product_id_value
}
}
pub fn is_empty(&self) -> bool {
self.value.is_empty()
}
}
impl Property for ProductID {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
if self.is_empty() {
return Ok(());
}
f.write_str("PRODID")?;
macro_rules! fmt {
($c:tt, $p:ident) => {
fmt_g!($c, Parameter, self, $p, f);
};
}
fmt!(2, any);
f.write_char(':')?;
Value::fmt(&self.value, f)?;
f.write_str("\r\n")?;
Ok(())
}
}
impl Display for ProductID {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
Property::fmt(self, f)
}
}
impl Validated for ProductID {}
impl ValidatedWrapper for ProductID {
type Error = &'static str;
fn from_string(_from_string_input: String) -> Result<Self, Self::Error> {
unimplemented!();
}
fn from_str(_from_str_input: &str) -> Result<Self, Self::Error> {
unimplemented!();
}
}