//! DHCP types for subnet configuration

use serde::{Deserialize, Serialize};

/// DHCP options for a subnet
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct DhcpOptions {
    /// CIDR block for DHCP
    pub cidr: String,

    /// Gateway/router IP address
    pub router: Option<String>,

    /// DNS server addresses
    pub dns_servers: Vec<String>,

    /// DHCP lease time in seconds
    pub lease_time: u32,

    /// Domain name for DHCP clients
    pub domain_name: Option<String>,
}

impl Default for DhcpOptions {
    fn default() -> Self {
        Self {
            cidr: String::new(),
            router: None,
            dns_servers: vec!["8.8.8.8".to_string()], // Default to Google DNS
            lease_time: 86400, // 24 hours
            domain_name: None,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_dhcp_options_default() {
        let opts = DhcpOptions::default();
        assert_eq!(opts.lease_time, 86400);
        assert_eq!(opts.dns_servers, vec!["8.8.8.8"]);
        assert!(opts.router.is_none());
        assert!(opts.domain_name.is_none());
    }

    #[test]
    fn test_dhcp_options_serialization() {
        let opts = DhcpOptions {
            cidr: "192.168.1.0/24".to_string(),
            router: Some("192.168.1.1".to_string()),
            dns_servers: vec!["8.8.8.8".to_string(), "8.8.4.4".to_string()],
            lease_time: 3600,
            domain_name: Some("example.com".to_string()),
        };

        let json = serde_json::to_string(&opts).unwrap();
        let deserialized: DhcpOptions = serde_json::from_str(&json).unwrap();
        assert_eq!(opts, deserialized);
    }
}
