1use serde::{Deserialize, Serialize};
2use tokio_util::sync::CancellationToken;
3
4use crate::{Result, rest::RestTransport};
5
6#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
8#[serde(rename_all = "lowercase")]
9pub enum ErpcPlan {
10 Business,
12 Developer,
14 Free,
16 Pro,
18}
19
20#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
22pub struct TokenBalance {
23 pub max_tokens: u64,
25 pub next_refill_at: Option<String>,
27 pub plan: ErpcPlan,
29 pub remaining_tokens: u64,
31}
32
33#[derive(Clone)]
35pub struct AccountClient {
36 transport: RestTransport,
37}
38
39impl AccountClient {
40 pub(crate) const fn new(transport: RestTransport) -> Self {
41 Self { transport }
42 }
43
44 pub async fn get_token_balance(&self) -> Result<TokenBalance> {
46 self.get_token_balance_with(None).await
47 }
48
49 pub async fn get_token_balance_with(
51 &self,
52 cancellation: Option<&CancellationToken>,
53 ) -> Result<TokenBalance> {
54 self.transport
55 .get("/v3/erpc/token-balance", Vec::new(), cancellation)
56 .await
57 }
58}