use nostr_rs_client::{Error as ClientError, Pool, Url};
use nostr_rs_types::{client::Subscribe, Response};

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("Nostr: {0}")]
    Addr(#[from] nostr_rs_types::types::addr::Error),

    #[error("client: {0}")]
    Client(#[from] ClientError),
}

#[tokio::main]
async fn main() {
    env_logger::init();
    let mut clients = Pool::new_with_clients(vec![
        Url::parse("wss://relay.damus.io/").expect("valid url"),
        Url::parse("wss://brb.io").expect("valid url"),
        Url::parse("wss://nos.lol").expect("valid url"),
        Url::parse("wss://relay.current.fyi").expect("valid url"),
        Url::parse("wss://eden.nostr.land").expect("valid url"),
        Url::parse("wss://relay.snort.social").expect("valid url"),
    ]);

    let _ = clients.subscribe(Subscribe::default().into()).await;

    loop {
        if let Some((msg, relayed_by)) = clients.recv().await {
            match msg {
                Response::Event(x) => {
                    println!("{} => {:?}", relayed_by, x);
                }
                Response::EndOfStoredEvents(_) => {}
                msg => {
                    println!("{} {:?}", relayed_by, msg);
                }
            }
        }
    }
}
