use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct IncomingMessage {
pub id: uuid::Uuid,
pub channel: String,
pub user_id: String,
pub content: String,
pub timestamp: DateTime<Utc>,
#[serde(default)]
pub metadata: HashMap<String, String>,
}
impl IncomingMessage {
pub fn new(
channel: impl Into<String>,
user_id: impl Into<String>,
content: impl Into<String>,
) -> Self {
Self {
id: uuid::Uuid::new_v4(),
channel: channel.into(),
user_id: user_id.into(),
content: content.into(),
timestamp: Utc::now(),
metadata: HashMap::new(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OutgoingMessage {
pub id: uuid::Uuid,
pub channel: String,
pub user_id: String,
pub content: String,
pub timestamp: DateTime<Utc>,
#[serde(default)]
pub metadata: HashMap<String, String>,
}
impl OutgoingMessage {
pub fn new(
channel: impl Into<String>,
user_id: impl Into<String>,
content: impl Into<String>,
) -> Self {
Self {
id: uuid::Uuid::new_v4(),
channel: channel.into(),
user_id: user_id.into(),
content: content.into(),
timestamp: Utc::now(),
metadata: HashMap::new(),
}
}
pub fn with_metadata(
channel: impl Into<String>,
user_id: impl Into<String>,
content: impl Into<String>,
metadata: HashMap<String, String>,
) -> Self {
Self {
id: uuid::Uuid::new_v4(),
channel: channel.into(),
user_id: user_id.into(),
content: content.into(),
timestamp: Utc::now(),
metadata,
}
}
}