use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TokenGauge {
    pub used_tokens: u64,
    pub quota_tokens: u64,
    pub reset_at: String,
    pub overage_allowed: bool,
    pub tier: String,
}

impl TokenGauge {
    pub fn usage_pct(&self) -> f64 {
        if self.quota_tokens == 0 {
            return 0.0;
        }
        (self.used_tokens as f64 / self.quota_tokens as f64 * 100.0).min(100.0)
    }

    pub fn remaining(&self) -> u64 {
        self.quota_tokens.saturating_sub(self.used_tokens)
    }

    pub fn is_over_limit(&self) -> bool {
        self.used_tokens > self.quota_tokens
    }
}
