use serde::{Deserialize, Serialize};
use crate::invoice::{Condition, Label};
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct Parcel {
pub label: Label,
pub conditions: Option<Condition>,
}
impl Parcel {
pub fn member_of(&self, group: &str) -> bool {
match &self.conditions {
Some(conditions) => match &conditions.member_of {
Some(groups) => groups.iter().any(|g| *g == group),
None => false,
},
None => false,
}
}
pub fn is_global_group(&self) -> bool {
match &self.conditions {
Some(conditions) => match &conditions.member_of {
Some(groups) => groups.is_empty(),
None => true,
},
None => true,
}
}
}