1use serde::{Deserialize, Serialize};
7
8use crate::client::Client;
9use crate::error::Result;
10
11#[derive(Debug, Clone, Deserialize)]
13pub struct CreditPack {
14 pub id: String,
16
17 #[serde(default)]
19 pub name: Option<String>,
20
21 #[serde(default)]
23 pub price_usd: f64,
24
25 #[serde(default)]
27 pub credit_ticks: i64,
28
29 #[serde(default)]
31 pub description: Option<String>,
32}
33
34#[derive(Debug, Clone, Deserialize)]
36pub struct CreditPacksResponse {
37 pub packs: Vec<CreditPack>,
39}
40
41#[derive(Debug, Clone, Serialize)]
43pub struct CreditPurchaseRequest {
44 pub pack_id: String,
46
47 #[serde(skip_serializing_if = "Option::is_none")]
49 pub success_url: Option<String>,
50
51 #[serde(skip_serializing_if = "Option::is_none")]
53 pub cancel_url: Option<String>,
54}
55
56#[derive(Debug, Clone, Deserialize)]
58pub struct CreditPurchaseResponse {
59 pub checkout_url: String,
61}
62
63#[derive(Debug, Clone, Deserialize)]
65pub struct CreditBalanceResponse {
66 pub balance_ticks: i64,
68
69 pub balance_usd: f64,
71}
72
73#[derive(Debug, Clone, Deserialize)]
75pub struct CreditTier {
76 #[serde(default)]
78 pub name: Option<String>,
79
80 #[serde(default)]
82 pub min_balance: i64,
83
84 #[serde(default)]
86 pub discount_percent: f64,
87
88 #[serde(flatten)]
90 pub extra: serde_json::Value,
91}
92
93#[derive(Debug, Clone, Deserialize)]
95pub struct CreditTiersResponse {
96 pub tiers: Vec<CreditTier>,
98}
99
100#[derive(Debug, Clone, Serialize)]
102pub struct DevProgramApplyRequest {
103 pub use_case: String,
105
106 #[serde(skip_serializing_if = "Option::is_none")]
108 pub company: Option<String>,
109
110 #[serde(skip_serializing_if = "Option::is_none")]
112 pub expected_usd: Option<f64>,
113
114 #[serde(skip_serializing_if = "Option::is_none")]
116 pub website: Option<String>,
117}
118
119#[derive(Debug, Clone, Deserialize)]
121pub struct DevProgramApplyResponse {
122 pub status: String,
124}
125
126impl Client {
127 pub async fn credit_packs(&self) -> Result<CreditPacksResponse> {
129 let (resp, _meta) = self
130 .get_json::<CreditPacksResponse>("/qai/v1/credits/packs")
131 .await?;
132 Ok(resp)
133 }
134
135 pub async fn credit_purchase(&self, req: &CreditPurchaseRequest) -> Result<CreditPurchaseResponse> {
137 let (resp, _meta) = self
138 .post_json::<CreditPurchaseRequest, CreditPurchaseResponse>(
139 "/qai/v1/credits/purchase",
140 req,
141 )
142 .await?;
143 Ok(resp)
144 }
145
146 pub async fn credit_balance(&self) -> Result<CreditBalanceResponse> {
148 let (resp, _meta) = self
149 .get_json::<CreditBalanceResponse>("/qai/v1/credits/balance")
150 .await?;
151 Ok(resp)
152 }
153
154 pub async fn credit_tiers(&self) -> Result<CreditTiersResponse> {
156 let (resp, _meta) = self
157 .get_json::<CreditTiersResponse>("/qai/v1/credits/tiers")
158 .await?;
159 Ok(resp)
160 }
161
162 pub async fn dev_program_apply(&self, req: &DevProgramApplyRequest) -> Result<DevProgramApplyResponse> {
164 let (resp, _meta) = self
165 .post_json::<DevProgramApplyRequest, DevProgramApplyResponse>(
166 "/qai/v1/credits/dev-program",
167 req,
168 )
169 .await?;
170 Ok(resp)
171 }
172}