use std::collections::HashMap;
use async_trait::async_trait;
use crate::error::SessionError;
use crate::types::{SessionQAEntry, SessionTraceStep, UsedGraphElementIds};
#[derive(Debug, Clone, Default)]
pub struct SessionQAUpdate {
pub question: Option<String>,
pub answer: Option<String>,
pub context: Option<Option<String>>,
pub feedback_text: Option<Option<String>>,
pub feedback_score: Option<Option<i32>>,
pub used_graph_element_ids: Option<Option<UsedGraphElementIds>>,
pub memify_metadata: Option<Option<HashMap<String, bool>>>,
}
#[async_trait]
pub trait SessionStore: Send + Sync {
async fn create_qa_entry(
&self,
session_id: &str,
user_id: Option<&str>,
question: &str,
answer: &str,
context: Option<&str>,
) -> Result<String, SessionError>;
async fn get_latest_qa_entries(
&self,
session_id: &str,
user_id: Option<&str>,
last_n: usize,
) -> Result<Vec<SessionQAEntry>, SessionError>;
async fn get_all_qa_entries(
&self,
session_id: &str,
user_id: Option<&str>,
) -> Result<Vec<SessionQAEntry>, SessionError>;
async fn delete_session(
&self,
session_id: &str,
user_id: Option<&str>,
) -> Result<bool, SessionError>;
async fn delete_qa_entry(
&self,
session_id: &str,
user_id: Option<&str>,
qa_id: &str,
) -> Result<bool, SessionError>;
async fn prune(&self) -> Result<(), SessionError>;
async fn update_qa_entry(
&self,
session_id: &str,
user_id: Option<&str>,
qa_id: &str,
updates: SessionQAUpdate,
) -> Result<bool, SessionError>;
async fn latest_qa_id(
&self,
session_id: &str,
user_id: Option<&str>,
) -> Result<Option<String>, SessionError> {
let entries = self.get_latest_qa_entries(session_id, user_id, 1).await?;
Ok(entries.into_iter().next().map(|e| e.id.to_string()))
}
async fn get_graph_context(
&self,
session_id: &str,
user_id: Option<&str>,
) -> Result<Option<String>, SessionError>;
async fn set_graph_context(
&self,
session_id: &str,
user_id: Option<&str>,
context: &str,
) -> Result<(), SessionError>;
async fn save_trace_step(
&self,
user_id: &str,
session_id: &str,
step: SessionTraceStep,
) -> Result<String, SessionError> {
let _ = (user_id, session_id, step);
Err(SessionError::StoreError(
"save_trace_step not implemented for this backend".into(),
))
}
async fn read_trace_steps(
&self,
user_id: &str,
session_id: &str,
) -> Result<Vec<SessionTraceStep>, SessionError> {
let _ = (user_id, session_id);
Err(SessionError::StoreError(
"read_trace_steps not implemented for this backend".into(),
))
}
}