use crate::{active_children, arg_of, child_block, statement_words, value_after};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Ieee8023ad {
pub aggregated_interface: Option<String>,
pub role: Option<String>,
pub link_index: Option<String>,
pub distribution_list: Option<String>,
pub lacp_port_priority: Option<String>,
}
pub(super) fn parse_ieee_802_3ad(options: &ConfigLine) -> Option<Ieee8023ad> {
let statement = active_children(options).find(|c| c.text == "802.3ad" || c.arg("802.3ad").is_some())?;
let words = statement_words(options, "802.3ad")?;
Some(Ieee8023ad {
aggregated_interface: words.iter().find(|w| w.starts_with("ae")).map(|w| w.to_string()),
role: words
.iter()
.find(|w| matches!(**w, "primary" | "backup"))
.map(|w| w.to_string()),
link_index: value_after(&words, "link-index"),
distribution_list: value_after(&words, "distribution-list"),
lacp_port_priority: child_block(statement, "lacp")
.and_then(|lacp| arg_of(lacp, "port-priority"))
.map(str::to_string),
})
}