use std::collections::HashMap;
use std::fmt::Display;
use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct Email<'a> {
pub summary: Option<&'a str>,
pub greeting: Option<Greeting<'a>>,
pub intros: Option<Vec<&'a str>>,
pub highlight: Option<&'a str>,
pub dictionary: Option<Vec<(&'a str, &'a str)>>,
pub tables: Option<Vec<Table<'a>>>,
pub actions: Option<Vec<Action<'a>>>,
pub outros: Option<Vec<&'a str>>,
pub signature: Option<&'a str>,
pub go_to_action: Option<GoToAction<'a>>,
}
#[derive(Debug, Clone, Serialize)]
pub struct TableColumns<'a> {
pub custom_width: Option<HashMap<&'a str, &'a str>>,
pub custom_alignment: Option<HashMap<&'a str, &'a str>>,
}
#[derive(Debug, Clone, Serialize)]
pub struct Table<'a> {
pub title: &'a str,
pub data: Vec<HashMap<&'a str, &'a str>>,
pub columns: Option<TableColumns<'a>>,
}
#[derive(Debug, Clone)]
pub enum Greeting<'a> {
Name(&'a str),
Custom(&'a str),
}
impl Display for Greeting<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Greeting::Name(name) => write!(f, "Hey {name},"),
Greeting::Custom(custom) => f.write_str(custom),
}
}
}
impl Serialize for Greeting<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.collect_str(self)
}
}
#[derive(Debug, Default, Clone, Serialize)]
pub struct Action<'a> {
pub text: &'a str,
pub link: &'a str,
pub instructions: Option<&'a str>,
pub color: Option<(&'a str, &'a str)>,
}
#[derive(Debug, Clone, Serialize)]
pub struct GoToAction<'a> {
pub text: &'a str,
pub link: &'a str,
pub description: &'a str,
}