use nostr_sdk::prelude::{RelayUrl, Url};

pub fn parse_relays(data: &str) -> Vec<RelayUrl> {
    let relays: Vec<String> = serde_json::from_str(data).unwrap();

    relays
        .iter()
        .filter_map(|url| RelayUrl::parse(url).ok())
        .collect()
}

pub fn parse_urls(data: &str) -> Vec<Url> {
    let urls: Vec<String> = serde_json::from_str(data).unwrap();

    urls.iter().filter_map(|url| Url::parse(url).ok()).collect()
}

pub fn default_relays() -> Vec<RelayUrl> {
    parse_relays(include_str!("../data/relays/default.json"))
}

pub fn popular_relays() -> Vec<RelayUrl> {
    parse_relays(include_str!("../data/relays/popular.json"))
}

pub fn blossom_servers() -> Vec<Url> {
    parse_urls(include_str!("../data/blossom/servers.json"))
}
