use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum EventType {
Add,
Update,
Delete,
}
impl EventType {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Add => "add",
Self::Update => "update",
Self::Delete => "delete",
}
}
}
impl std::str::FromStr for EventType {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"add" => Ok(Self::Add),
"update" => Ok(Self::Update),
"delete" => Ok(Self::Delete),
other => Err(format!("unknown event type: {other}")),
}
}
}
impl std::fmt::Display for EventType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Event {
pub id: Uuid,
pub memory_id: Uuid,
pub event_type: EventType,
pub old_content: Option<String>,
pub new_content: Option<String>,
pub timestamp: DateTime<Utc>,
}