use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Dialogue {
pub speaker: String,
pub content: String,
pub timestamp: Option<DateTime<Utc>>,
}
impl Dialogue {
#[must_use]
pub fn new(speaker: impl Into<String>, content: impl Into<String>) -> Self {
Self {
speaker: speaker.into(),
content: content.into(),
timestamp: None,
}
}
#[must_use]
pub const fn with_timestamp(mut self, ts: DateTime<Utc>) -> Self {
self.timestamp = Some(ts);
self
}
#[must_use]
pub(crate) fn format_for_prompt(&self) -> String {
self.timestamp.map_or_else(
|| format!("{}: {}", self.speaker, self.content),
|ts| {
format!(
"[{} {}] {}: {}",
ts.format("%d %B %Y"),
ts.format("%H:%M"),
self.speaker,
self.content,
)
},
)
}
}
impl std::fmt::Display for Dialogue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}: {}", self.speaker, self.content)
}
}