use api::*;
#[tokio::main]
pub async fn main() {
    let config = std::fs::read_to_string("config.toml").expect("Config.toml");
    let config: JellyfinConfig = toml::from_str(&config).expect("Failed to parse config.toml");

    let mut jellyfin = JellyfinClient::new_with_config(config);
    jellyfin
        .authenticate_with_cached_token(".session")
        .await
        .expect("Auth");
    let items = jellyfin.items(None).await.expect("Items");
    std::fs::write(
        "items.json",
        serde_json::to_string_pretty(&items).expect("Serialize items"),
    );
    for item in items {
        println!("{}: {:?}", item.id, item.name);
        let items = jellyfin.items(item.id).await.expect("Items");
        std::fs::write(
            format!("items_{:?}.json", item.name),
            serde_json::to_string_pretty(&items).expect("Serialize items"),
        );
        // for item in items {
        //     println!("  {}: {:?}", item.id, item.name);
        //     std::fs::write(
        //         format!("item_{}.json", item.id),
        //         serde_json::to_string_pretty(&item).expect("Serialize item"),
        //     );
        // }
    }
}
