use crate::csaf::traits::util::impl_optional_str_field_getter;
use crate::csaf::traits::util::not_present_20::NotPresentInCsaf20;
use crate::schema::csaf2_1::schema::SharingGroup as SharingGroup21;
use uuid::Uuid;
pub const SG_NAME_PUBLIC: &str = "Public";
pub const SG_NAME_PRIVATE: &str = "No sharing allowed";
pub trait SharingGroupTrait {
fn get_id(&self) -> &Uuid;
fn get_name(&self) -> Option<&str>;
fn is_name_public(&self) -> bool {
self.get_name().is_some_and(|name| name == SG_NAME_PUBLIC)
}
fn is_name_private(&self) -> bool {
self.get_name().is_some_and(|name| name == SG_NAME_PRIVATE)
}
}
impl SharingGroupTrait for NotPresentInCsaf20 {
fn get_id(&self) -> &Uuid {
self.into_any()
}
fn get_name(&self) -> Option<&str> {
self.into_any()
}
}
impl SharingGroupTrait for SharingGroup21 {
fn get_id(&self) -> &Uuid {
&self.id
}
impl_optional_str_field_getter!(get_name, name);
}