use serde::{Deserialize, Serialize};
use crate::passport::Passport;
use crate::product_group::ProductGroup;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ProductIdentity {
pub product_group: ProductGroup,
pub identifier: String,
pub batch_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub serial_number: Option<String>,
}
impl ProductIdentity {
pub fn from_passport(passport: &Passport) -> Option<Self> {
let identifier = passport
.product_group_data
.as_ref()?
.product_identifier()?
.as_str()
.to_owned();
Some(Self {
product_group: passport.product_group.clone(),
identifier,
batch_id: passport.batch_id.clone(),
serial_number: passport.serial_number.clone(),
})
}
}