use crate::error::FloopError;
use crate::Client;
use serde::Deserialize;
use serde_json::Value;
#[derive(Debug, Clone, Deserialize)]
pub struct SubscriptionPlan {
pub status: String,
#[serde(default, rename = "billingPeriod")]
pub billing_period: Option<String>,
#[serde(rename = "currentPeriodStart")]
pub current_period_start: String,
#[serde(rename = "currentPeriodEnd")]
pub current_period_end: String,
#[serde(default, rename = "canceledAt")]
pub canceled_at: Option<String>,
#[serde(rename = "planName")]
pub plan_name: String,
#[serde(rename = "planDisplayName")]
pub plan_display_name: String,
#[serde(rename = "priceMonthly")]
pub price_monthly: i64,
#[serde(rename = "priceAnnual")]
pub price_annual: i64,
#[serde(rename = "monthlyCredits")]
pub monthly_credits: i64,
#[serde(rename = "maxProjects")]
pub max_projects: i64,
#[serde(rename = "maxStorageMb")]
pub max_storage_mb: i64,
#[serde(rename = "maxBandwidthMb")]
pub max_bandwidth_mb: i64,
#[serde(rename = "creditRolloverMonths")]
pub credit_rollover_months: i64,
pub features: Value,
}
#[derive(Debug, Clone, Deserialize)]
pub struct SubscriptionCredits {
pub current: i64,
#[serde(rename = "rolledOver")]
pub rolled_over: i64,
pub total: i64,
#[serde(default, rename = "rolloverExpiresAt")]
pub rollover_expires_at: Option<String>,
#[serde(rename = "lifetimeUsed")]
pub lifetime_used: i64,
}
#[derive(Debug, Clone, Deserialize)]
pub struct CurrentSubscription {
#[serde(default)]
pub subscription: Option<SubscriptionPlan>,
#[serde(default)]
pub credits: Option<SubscriptionCredits>,
}
pub struct Subscriptions<'c> {
pub(crate) client: &'c Client,
}
impl<'c> Subscriptions<'c> {
pub async fn current(&self) -> Result<CurrentSubscription, FloopError> {
self.client
.request_json(reqwest::Method::GET, "/api/v1/subscriptions/current", None)
.await
}
}