use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct MemorySession {
pub id: String,
pub started_at: DateTime<Utc>,
pub ended_at: Option<DateTime<Utc>>,
pub caller_id: String,
pub title: Option<String>,
pub summary: Option<String>,
pub outcome: SessionOutcome,
#[serde(default)]
pub metadata: Value,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct NewMemorySession {
pub caller_id: String,
#[serde(default)]
pub title: Option<String>,
#[serde(default)]
pub metadata: Value,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
pub enum SessionOutcome {
Open,
Success,
Failure,
Aborted,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
pub struct SessionFilter {
#[serde(default)]
pub caller_id: Option<String>,
#[serde(default)]
pub outcome: Option<SessionOutcome>,
#[serde(default)]
pub since: Option<DateTime<Utc>>,
#[serde(default)]
pub until: Option<DateTime<Utc>>,
#[serde(default)]
pub open_only: bool,
#[serde(default)]
pub limit: Option<usize>,
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
#[test]
fn outcome_serializes_snake_case() {
assert_eq!(
serde_json::to_value(SessionOutcome::Open).unwrap(),
json!("open")
);
assert_eq!(
serde_json::to_value(SessionOutcome::Aborted).unwrap(),
json!("aborted")
);
}
#[test]
fn filter_defaults() {
let f = SessionFilter::default();
assert!(f.caller_id.is_none());
assert!(f.outcome.is_none());
assert!(!f.open_only);
assert!(f.limit.is_none());
}
}