use std::sync::Arc;
use crate::error::Result;
use crate::http::HttpClient;
use crate::types::{
BillingUsage, CancelResponse, CurrentPlan, Plan, UpgradeRequest, UpgradeResponse,
VerifyResponse,
};
#[derive(Clone)]
pub struct BillingResource {
pub(crate) http: Arc<HttpClient>,
}
impl BillingResource {
pub async fn plans(&self) -> Result<Vec<Plan>> {
self.http.get("/billing/plans", None).await
}
pub async fn plan(&self, jwt: &str) -> Result<CurrentPlan> {
self.http.get("/billing/plan", Some(jwt)).await
}
pub async fn usage(&self, jwt: &str) -> Result<BillingUsage> {
self.http.get("/billing/usage", Some(jwt)).await
}
pub async fn upgrade(&self, request: UpgradeRequest, jwt: &str) -> Result<UpgradeResponse> {
self.http.post("/billing/upgrade", &request, Some(jwt)).await
}
pub async fn verify(&self, jwt: &str) -> Result<VerifyResponse> {
self.http.get("/billing/verify", Some(jwt)).await
}
pub async fn cancel(&self, jwt: &str) -> Result<CancelResponse> {
self.http.post("/billing/cancel", &serde_json::json!({}), Some(jwt)).await
}
}