use crate::{arg_of, args_of, named_children};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct StaticSubscriberProfile {
pub name: String,
pub aggregate_clients: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct StaticSubscriberGroup {
pub name: String,
pub access_profile: Option<String>,
pub dynamic_profiles: Vec<StaticSubscriberProfile>,
pub interfaces: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct StaticSubscribers {
pub access_profile: Option<String>,
pub service_profile: Option<String>,
pub groups: Vec<StaticSubscriberGroup>,
}
pub(super) fn parse_static_subscribers(subscribers: &ConfigLine) -> StaticSubscribers {
StaticSubscribers {
access_profile: arg_of(subscribers, "access-profile").map(str::to_string),
service_profile: arg_of(subscribers, "service-profile").map(str::to_string),
groups: named_children(subscribers, "group")
.map(|(name, group)| StaticSubscriberGroup {
name: name.to_string(),
access_profile: arg_of(group, "access-profile").map(str::to_string),
dynamic_profiles: named_children(group, "dynamic-profile")
.map(|(name, profile)| StaticSubscriberProfile {
name: name.to_string(),
aggregate_clients: arg_of(profile, "aggregate-clients").map(str::to_string),
})
.collect(),
interfaces: args_of(group, "interface").into_iter().map(str::to_string).collect(),
})
.collect(),
}
}