use opnsense_config_xml::{Host, OPNsense};

pub struct DnsConfig<'a> {
    opnsense: &'a mut OPNsense,
}

impl<'a> DnsConfig<'a> {
    pub fn new(opnsense: &'a mut OPNsense) -> Self {
        Self { opnsense }
    }

    pub fn register_hosts(&mut self, mut hosts: Vec<Host>) {
        let unbound = match &mut self.opnsense.opnsense.unboundplus {
            Some(unbound) => unbound,
            None => todo!("Handle case where unboundplus is not used"),
        };
        unbound.hosts.hosts.append(&mut hosts);
    }

    pub fn get_hosts(&self) -> Vec<Host> {
        let unbound = match &self.opnsense.opnsense.unboundplus {
            Some(unbound) => unbound,
            None => todo!("Handle case where unboundplus is not used"),
        };
        unbound.hosts.hosts.clone()
    }

    pub fn register_dhcp_leases(&mut self, register: bool) {
        let unbound = match &mut self.opnsense.opnsense.unboundplus {
            Some(unbound) => unbound,
            None => todo!("Handle case where unboundplus is not used"),
        };

        unbound.general.regdhcp = Some(register as i8);
        unbound.general.regdhcpstatic = Some(register as i8);
    }
}
