use chanora_resolver::{setup_log, ChanoraResolver};

#[tokio::main]
async fn main() {
    setup_log();

    let input = std::env::args()
        .nth(1)
        .unwrap_or_else(|| "voice.teamspeak.com".into());

    let client = match ChanoraResolver::new() {
        Ok(client) => client,
        Err(err) => {
            tracing::error!(err = %err, "failed to initialize client");
            std::process::exit(1);
        }
    };

    match client.resolve_client_request(&input).await {
        Ok(resolution) => {
            let connect_addr = resolution.address;
            tracing::info!(
                input = %resolution.input,
                method = ?resolution.method,
                addr = %connect_addr,
                "client connection target"
            );

            // Direct tsclientlib handoff:
            // let mut connection = tsclientlib::Connection::build(connect_addr).connect()?;
            //
            // Chanora handoff:
            // let cfg = chanora_core::ConnectConfig {
            //     address: connect_addr,
            //     nickname,
            //     password,
            //     identity,
            //     ready_timeout,
            // };
            // let snapshot = session.connect(cfg).await?;
        }
        Err(err) => {
            tracing::error!(err = %err, "example lookup failed");
            std::process::exit(1);
        }
    }
}
