| use serde::{Deserialize, Serialize}; |
| use super::{token::TokenData, quota::QuotaData}; |
|
|
| |
| #[derive(Debug, Clone, Serialize, Deserialize)] |
| pub struct Account { |
| pub id: String, |
| pub email: String, |
| pub name: Option<String>, |
| pub token: TokenData, |
| pub quota: Option<QuotaData>, |
| pub created_at: i64, |
| pub last_used: i64, |
| } |
|
|
| impl Account { |
| pub fn new(id: String, email: String, token: TokenData) -> Self { |
| let now = chrono::Utc::now().timestamp(); |
| Self { |
| id, |
| email, |
| name: None, |
| token, |
| quota: None, |
| created_at: now, |
| last_used: now, |
| } |
| } |
|
|
| pub fn update_last_used(&mut self) { |
| self.last_used = chrono::Utc::now().timestamp(); |
| } |
|
|
| pub fn update_quota(&mut self, quota: QuotaData) { |
| self.quota = Some(quota); |
| } |
| } |
|
|
| |
| #[derive(Debug, Clone, Serialize, Deserialize)] |
| pub struct AccountIndex { |
| pub version: String, |
| pub accounts: Vec<AccountSummary>, |
| pub current_account_id: Option<String>, |
| } |
|
|
| |
| #[derive(Debug, Clone, Serialize, Deserialize)] |
| pub struct AccountSummary { |
| pub id: String, |
| pub email: String, |
| pub name: Option<String>, |
| pub created_at: i64, |
| pub last_used: i64, |
| } |
|
|
| impl AccountIndex { |
| pub fn new() -> Self { |
| Self { |
| version: "2.0".to_string(), |
| accounts: Vec::new(), |
| current_account_id: None, |
| } |
| } |
| } |
|
|
| impl Default for AccountIndex { |
| fn default() -> Self { |
| Self::new() |
| } |
| } |
|
|