use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use super::types::BudgetWindow;
use super::{ManagementClient, Result};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BudgetEnvelope {
pub id: String,
pub name: String,
pub window: BudgetWindow,
pub limit_micro_usd: i64,
#[serde(default)]
pub disabled_at: Option<DateTime<Utc>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BudgetListResponse {
pub data: Vec<BudgetEnvelope>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateBudgetRequest {
pub name: String,
pub window: BudgetWindow,
pub limit_micro_usd: i64,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct UpdateBudgetRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub window: Option<BudgetWindow>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit_micro_usd: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteBudgetResponse {
pub deleted: bool,
}
impl ManagementClient {
pub async fn list_budgets(&self) -> Result<BudgetListResponse> {
let path = self.namespaced("/budgets")?;
self.get_json(&path).await
}
pub async fn get_budget(&self, id: &str) -> Result<BudgetEnvelope> {
let path = self.namespaced(&format!("/budgets/{id}"))?;
self.get_json(&path).await
}
pub async fn create_budget(&self, body: &CreateBudgetRequest) -> Result<BudgetEnvelope> {
let path = self.namespaced("/budgets")?;
self.post_json(&path, body).await
}
pub async fn update_budget(
&self,
id: &str,
body: &UpdateBudgetRequest,
) -> Result<BudgetEnvelope> {
let path = self.namespaced(&format!("/budgets/{id}"))?;
self.put_json(&path, body).await
}
pub async fn delete_budget(&self, id: &str) -> Result<DeleteBudgetResponse> {
let path = self.namespaced(&format!("/budgets/{id}"))?;
self.delete_json(&path).await
}
}