use crate::{arg_of, child_block, has_leaf, secret_value, statement_words, toggle, value_after};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct RsvpPeerInterface {
pub name: String,
pub disable: bool,
pub aggregate: Option<bool>,
pub has_authentication_key: bool,
pub authentication_key: Option<crate::Secret>,
pub dynamic_bidirectional_transport: bool,
pub dynamic_bidirectional_transport_template: Option<String>,
pub hello_interval: Option<String>,
pub reliable: Option<bool>,
}
pub(super) fn parse_peer_interface(name: &str, peer: &ConfigLine) -> RsvpPeerInterface {
let transport = statement_words(peer, "dynamic-bidirectional-transport");
RsvpPeerInterface {
name: name.to_string(),
disable: has_leaf(peer, "disable"),
aggregate: toggle(peer, "aggregate"),
has_authentication_key: arg_of(peer, "authentication-key").is_some(),
authentication_key: secret_value(arg_of(peer, "authentication-key")),
dynamic_bidirectional_transport: child_block(peer, "dynamic-bidirectional-transport").is_some()
|| transport.is_some(),
dynamic_bidirectional_transport_template: transport.and_then(|words| value_after(&words, "template")),
hello_interval: arg_of(peer, "hello-interval").map(str::to_string),
reliable: toggle(peer, "reliable"),
}
}