use crate::{Param, ParamError, ParamList};
#[derive(Debug)]
pub enum SendMessageParam<'a, T: ?Sized> where T: serde::Serialize {
From(&'a str),
To(&'a str),
Cc(&'a str),
Bcc(&'a str),
Subject(&'a str),
Text(&'a str),
Html(&'a str),
AmpHtml(&'a str),
Attachment(&'a str),
Inline(&'a str),
Template(&'a str),
TVersion(&'a str),
TText(&'a str),
OTag(&'a str),
ODkim(bool),
ODeliveryTime(&'a str),
ODeliveryTimeOptimizePeriod(&'a str),
OTimeZoneLocalize(&'a str),
OTestMode(bool),
OTracking(bool),
OTrackingClicks(&'a str),
OTrackingOpens(bool),
ORequireTls(bool),
OSkipVerification(bool),
CustomHeader { key: &'a str, value: &'a str },
CustomVariable { key: &'a str, value: &'a str },
RecipientVariables(&'a T),
}
impl<'a, T: ?Sized> Param for SendMessageParam<'a, T> where T: serde::Serialize {
fn try_as_tuple(&self) -> Result<(String, String), ParamError> {
Ok(match self {
Self::From(v) => ("from".to_string(), v.to_string()),
Self::To(v) => ("to".to_string(), v.to_string()),
Self::Cc(v) => ("cc".to_string(), v.to_string()),
Self::Bcc(v) => ("bcc".to_string(), v.to_string()),
Self::Subject(v) => ("subject".to_string(), v.to_string()),
Self::Text(v) => ("text".to_string(), v.to_string()),
Self::Html(v) => ("html".to_string(), v.to_string()),
Self::AmpHtml(v) => ("amp-html".to_string(), v.to_string()),
Self::Attachment(v) => ("attachment".to_string(), v.to_string()),
Self::Inline(v) => ("inline".to_string(), v.to_string()),
Self::Template(v) => ("template".to_string(), v.to_string()),
Self::TVersion(v) => ("t:version".to_string(), v.to_string()),
Self::TText(v) => ("t:text".to_string(), v.to_string()),
Self::OTag(v) => ("o:tag".to_string(), v.to_string()),
Self::ODkim(v) => ("o:dkim".to_string(), if *v { "yes".to_string() } else { "no".to_string() }),
Self::ODeliveryTime(v) => ("o:delivery-time".to_string(), v.to_string()),
Self::ODeliveryTimeOptimizePeriod(v) => ("o:delivery-time-optimize-period".to_string(), v.to_string()),
Self::OTimeZoneLocalize(v) => ("o:time-zone-localize".to_string(), v.to_string()),
Self::OTestMode(v) => ("o:testmode".to_string(), if *v { "yes".to_string() } else { "no".to_string() }),
Self::OTracking(v) => ("o:tracking".to_string(), v.to_string()),
Self::OTrackingClicks(v) => ("o:tracking-clicks".to_string(), v.to_string()),
Self::OTrackingOpens(v) => ("o:tracking-open".to_string(), if *v { "yes".to_string() } else { "no".to_string() }),
Self::ORequireTls(v) => ("o:require-tls".to_string(), if *v { "yes".to_string() } else { "no".to_string() }),
Self::OSkipVerification(v) => ("o:skip-verification".to_string(), if *v { "yes".to_string() } else { "no".to_string() }),
Self::CustomHeader { key, value } => (format!("h:{}", key), value.to_string()),
Self::CustomVariable { key, value } => (format!("v:{}", key), value.to_string()),
Self::RecipientVariables(v) => {
let v = serde_json::to_string(v)
.map_err(|error| ParamError::InvalidJson("recipient-variables".to_string(), error))?;
("recipient-variables".to_string(), v)
},
})
}
}
#[derive(Debug)]
pub struct SendMessageParamList<'a, T: ?Sized> where T: serde::Serialize {
pub values: Vec<SendMessageParam<'a, T>>,
}
impl<'a, T: ?Sized> Default for SendMessageParamList<'a, T> where T: serde::Serialize {
fn default() -> Self {
Self {
values: vec![],
}
}
}
impl<'a, T: ?Sized> ParamList for SendMessageParamList<'a, T> where T: serde::Serialize {
type ParamType = SendMessageParam<'a, T>;
fn add(mut self, param: Self::ParamType) -> Self {
self.values.push(param);
self
}
}
#[derive(Debug, Deserialize, Serialize)]
pub struct SendMessageResponse {
pub id: String,
pub message: String,
}