//! Method to get TLD list from preset

use crate::types::tld_preset::TldPreset;

impl TldPreset {
    /// Get the list of TLDs for this preset
    ///
    /// # Returns
    ///
    /// Returns a `Vec<String>` containing the TLDs for this preset.
    ///
    /// # Examples
    ///
    /// ```
    /// use lazydomain::types::TldPreset;
    ///
    /// let preset = TldPreset::Startup;
    /// let tlds = preset.get_tlds();
    /// assert!(tlds.contains(&"io".to_string()));
    /// assert!(tlds.contains(&"ai".to_string()));
    /// ```
    pub fn get_tlds(&self) -> Vec<String> {
        let tlds: Vec<&str> = match self {
            TldPreset::Startup => vec![
                "io", "co", "app", "dev", "tech", "ai",
            ],
            TldPreset::Enterprise => vec![
                "com", "net", "org", "biz", "pro",
            ],
            TldPreset::Tech => vec![
                "dev", "app", "cloud", "digital", "tech", "codes",
            ],
            TldPreset::Popular => vec![
                "com", "net", "org", "io", "co", "ai", "xyz",
            ],
            TldPreset::All => vec![
                "com", "net", "org", "info", "biz", "name", "mobi", "pro",
                "io", "co", "dev", "app", "tech", "cloud", "digital", "ai",
                "xyz", "online", "site", "store", "shop", "club", "live",
                "solutions", "services", "consulting", "management", "ventures",
            ],
            TldPreset::Custom(tlds) => return tlds.clone(),
        };
        
        tlds.into_iter().map(|s| s.to_string()).collect()
    }
}

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

    #[test]
    fn test_startup_preset() {
        let preset = TldPreset::Startup;
        let tlds = preset.get_tlds();
        assert!(tlds.contains(&"io".to_string()));
        assert!(tlds.contains(&"ai".to_string()));
    }

    #[test]
    fn test_popular_preset() {
        let preset = TldPreset::Popular;
        let tlds = preset.get_tlds();
        assert!(tlds.contains(&"com".to_string()));
        assert!(tlds.contains(&"org".to_string()));
    }

    #[test]
    fn test_custom_preset() {
        let custom = vec!["xyz".to_string(), "test".to_string()];
        let preset = TldPreset::Custom(custom.clone());
        let tlds = preset.get_tlds();
        assert_eq!(tlds, custom);
    }
}
