use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Session {
pub id: Uuid,
pub label: Option<String>,
pub created_at: DateTime<Utc>,
pub last_active: DateTime<Utc>,
pub message_count: u64,
}
impl Session {
pub fn new(label: Option<String>) -> Self {
let now = Utc::now();
Self {
id: Uuid::new_v4(),
label,
created_at: now,
last_active: now,
message_count: 0,
}
}
pub fn touch(&mut self) {
self.last_active = Utc::now();
self.message_count += 1;
}
}
impl std::fmt::Display for Session {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let label = self.label.as_deref().unwrap_or("(untitled)");
write!(
f,
"Session {} [{}] — {} messages, created {}",
self.id,
label,
self.message_count,
self.created_at.format("%Y-%m-%d %H:%M:%S")
)
}
}