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 gtin: String,
pub batch_id: Option<String>,
}
impl ProductIdentity {
pub fn from_passport(passport: &Passport) -> Option<Self> {
let gtin = passport.product_group_data.as_ref()?.gtin()?.to_owned();
Some(Self {
product_group: passport.product_group.clone(),
gtin,
batch_id: passport.batch_id.clone(),
})
}
}