use std::sync::Arc;
use crate::error::FlowResult;
use crate::http::HttpClient;
use crate::resources::invoices::list_to_map;
use crate::types::*;
pub struct WalletService {
pub(crate) http: Arc<HttpClient>,
}
impl WalletService {
pub async fn generate(&self, params: GenerateWalletParams) -> FlowResult<Wallet> {
let data = self.http.post("/wallets/generate", Some(¶ms)).await?;
Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
}
pub async fn get(&self, id: &str) -> FlowResult<Wallet> {
let data = self.http.get(&format!("/wallets/{}", id), None).await?;
Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
}
pub async fn list(&self, params: Option<&ListParams>) -> FlowResult<PaginatedList<Wallet>> {
let map = params.map(list_to_map);
let data = self.http.get("/wallets", map.as_ref()).await?;
Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
}
pub async fn balance(&self, id: &str) -> FlowResult<Wallet> {
let data = self.http.get(&format!("/wallets/{}/balance", id), None).await?;
Ok(serde_json::from_slice(&data).map_err(|e| crate::error::FlowError::Other(e.to_string()))?)
}
}