use serde::{Deserialize, Serialize};
use smol_str::SmolStr;
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct TemplateVars {
pub session_id: Option<SmolStr>,
pub request_id: Option<SmolStr>,
pub project_cwd: Option<SmolStr>,
pub interaction_id: Option<SmolStr>,
pub account_id: Option<SmolStr>,
}
impl TemplateVars {
pub fn empty() -> Self {
Self::default()
}
pub fn is_empty(&self) -> bool {
self.session_id.is_none()
&& self.request_id.is_none()
&& self.project_cwd.is_none()
&& self.interaction_id.is_none()
&& self.account_id.is_none()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_is_empty() {
assert!(TemplateVars::empty().is_empty());
}
#[test]
fn populated_is_not_empty() {
let v = TemplateVars {
session_id: Some(SmolStr::new("ses_42")),
..Default::default()
};
assert!(!v.is_empty());
}
#[test]
fn round_trips_through_json() {
let v = TemplateVars {
session_id: Some("ses_42".into()),
request_id: Some("req_99".into()),
project_cwd: Some("/work".into()),
interaction_id: None,
account_id: Some("acct_1".into()),
};
let s = serde_json::to_string(&v).unwrap();
let back: TemplateVars = serde_json::from_str(&s).unwrap();
assert_eq!(v, back);
}
}