use chrono::{DateTime, Utc};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ChannelUser {
pub platform: String,
pub platform_user_id: String,
pub display_name: String,
pub username: Option<String>,
pub avatar_url: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct ChannelSession {
pub id: Uuid,
pub channel_user: ChannelUser,
pub agent_session_id: String,
pub created_at: DateTime<Utc>,
pub last_activity: DateTime<Utc>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub struct ConversationId {
pub platform: String,
pub channel_id: String,
pub server_id: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn channel_user_serde_roundtrip() {
let user = ChannelUser {
platform: "discord".to_string(),
platform_user_id: "123456".to_string(),
display_name: "Alice".to_string(),
username: Some("alice#1234".to_string()),
avatar_url: None,
};
let json = serde_json::to_string(&user).unwrap();
let deserialized: ChannelUser = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized.display_name, "Alice");
assert_eq!(deserialized.platform_user_id, "123456");
}
#[test]
fn channel_session_serde_roundtrip() {
let session = ChannelSession {
id: Uuid::new_v4(),
channel_user: ChannelUser {
platform: "telegram".to_string(),
platform_user_id: "789".to_string(),
display_name: "Bob".to_string(),
username: None,
avatar_url: None,
},
agent_session_id: "agent-sess-001".to_string(),
created_at: Utc::now(),
last_activity: Utc::now(),
};
let json = serde_json::to_string(&session).unwrap();
let deserialized: ChannelSession = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized.id, session.id);
assert_eq!(deserialized.agent_session_id, "agent-sess-001");
}
#[test]
fn conversation_id_serde_roundtrip() {
let conv = ConversationId {
platform: "slack".to_string(),
channel_id: "C01234".to_string(),
server_id: Some("T56789".to_string()),
};
let json = serde_json::to_string(&conv).unwrap();
let deserialized: ConversationId = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized, conv);
}
}