use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DataUsage {
pub remaining_gb: f64,
pub total_gb: f64,
pub used_gb: f64,
pub percentage: f64,
pub plan_name: Option<String>,
pub valid_until: Option<String>,
pub is_unlimited: bool,
}
impl DataUsage {
pub fn new(
remaining_gb: f64,
total_gb: f64,
plan_name: Option<String>,
valid_until: Option<String>,
) -> Self {
let used_gb = total_gb - remaining_gb;
let percentage = if total_gb > 0.0 {
(used_gb / total_gb) * 100.0
} else {
0.0
};
Self {
remaining_gb,
total_gb,
used_gb,
percentage,
plan_name,
valid_until,
is_unlimited: false,
}
}
pub fn new_unlimited(plan_name: Option<String>, valid_until: Option<String>) -> Self {
Self {
remaining_gb: 0.0,
total_gb: 0.0,
used_gb: 0.0,
percentage: 0.0,
plan_name,
valid_until,
is_unlimited: true,
}
}
pub fn remaining_percentage(&self) -> f64 {
100.0 - self.percentage
}
}