use crate::api::MyceliumClient;
use crate::error::AppResult;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PubkeyLookup {
    #[serde(rename = "NodePubKey")]
    pub node_pub_key: String,
}

impl MyceliumClient {
    /// Resolve the public key of an overlay node from its IPv6 address.
    pub async fn lookup_pubkey(&self, ip: &str) -> AppResult<PubkeyLookup> {
        let resp = self
            .http()
            .get(self.url(&format!("/pubkey/{ip}")))
            .send()
            .await?;
        Self::parse(resp).await
    }
}
