1use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use uuid::Uuid;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Session {
13 pub id: Uuid,
15 pub label: Option<String>,
17 pub created_at: DateTime<Utc>,
19 pub last_active: DateTime<Utc>,
21 pub message_count: u64,
23}
24
25impl Session {
26 pub fn new(label: Option<String>) -> Self {
28 let now = Utc::now();
29 Self {
30 id: Uuid::new_v4(),
31 label,
32 created_at: now,
33 last_active: now,
34 message_count: 0,
35 }
36 }
37
38 pub fn touch(&mut self) {
40 self.last_active = Utc::now();
41 self.message_count += 1;
42 }
43}
44
45impl std::fmt::Display for Session {
46 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47 let label = self.label.as_deref().unwrap_or("(untitled)");
48 write!(
49 f,
50 "Session {} [{}] — {} messages, created {}",
51 self.id,
52 label,
53 self.message_count,
54 self.created_at.format("%Y-%m-%d %H:%M:%S")
55 )
56 }
57}