extern crate log;
use clipboard_sync::ClipboardSync;
use std::net::IpAddr;
use trust_dns_resolver::{
    config::{ResolverConfig, ResolverOpts},
    Resolver,
};
use tokio::sync::{Mutex};
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    env_logger::init();
    // // 创建自定义 DNS 解析器
    // let resolver = Resolver::new(ResolverConfig::default(), ResolverOpts::default()).unwrap();

    // // 要解析的域名
    // let response = resolver.lookup_ip("www.baidu.com");
    // match response {
    //     Ok(response) => {
    //         for ip in response {
    //             match ip {
    //                 IpAddr::V4(v4) => println!("IPv4: {}", v4),
    //                 IpAddr::V6(v6) => println!("IPv6: {}", v6),
    //             }
    //         }
    //     }
    //     Err(e) => {
    //         println!("Error: {}", e);
    //     }
    // }

    let mut ins = ClipboardSync::new("172.19.36.79", "ekko.bao", "qwer12345;");
    match ins.login().await {
        Ok(()) => log::info!("登录成功"),
        Err(e) => {
            log::error!("登录失败: {}", e);
        }
    }
    let ctx = Arc::new(Mutex::new(ins));
    let handle = clipboard_sync::start_msg_sync(ctx.clone()).await.unwrap();
    let _ = handle.await;
    // 获取 Cookies
    //if let Some(cookies) = response.headers().get(COOKIE) {
    //    println!("Cookies: {:?}", cookies);
    //} else {
    //    println!("No cookies found.");
    //}
    Ok(())
}
