use crate::{child_block, has_leaf, toggle};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct MplsLogUpdown {
pub syslog: Option<bool>,
pub trap: bool,
pub trap_path_down: bool,
pub trap_path_up: bool,
pub no_trap_mpls_lsp_traps: bool,
pub no_trap_rfc3812_traps: bool,
}
pub(super) fn parse_log_updown(mpls: &ConfigLine) -> Option<MplsLogUpdown> {
let log = child_block(mpls, "log-updown")?;
let no_trap = child_block(log, "no-trap");
let in_no_trap = |flag: &str| no_trap.is_some_and(|block| has_leaf(block, flag));
Some(MplsLogUpdown {
syslog: toggle(log, "syslog"),
trap: has_leaf(log, "trap"),
trap_path_down: has_leaf(log, "trap-path-down"),
trap_path_up: has_leaf(log, "trap-path-up"),
no_trap_mpls_lsp_traps: in_no_trap("mpls-lsp-traps"),
no_trap_rfc3812_traps: in_no_trap("rfc3812-traps"),
})
}