use alloc::{string::String, vec::Vec};
use serde::{Deserialize, Deserializer, Serialize};
use crate::v1::{field::MsgraphField, rest::users::contacts::MsgraphSingleValueExtendedProperty};
pub mod attachments;
pub mod copy;
pub mod create;
pub mod create_mime;
pub mod delete;
pub mod delta;
pub mod get;
pub mod get_raw;
pub mod list;
pub mod r#move;
pub mod send;
pub mod update;
#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct MsgraphMessage {
#[serde(default, skip_serializing_if = "String::is_empty")]
pub id: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub change_key: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub subject: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub body_preview: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub body: Option<MsgraphItemBody>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub from: Option<MsgraphRecipient>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sender: Option<MsgraphRecipient>,
#[serde(default, skip_serializing_if = "MsgraphField::is_unset")]
#[cfg_attr(feature = "schemars", schemars(with = "Option<Vec<MsgraphRecipient>>"))]
pub to_recipients: MsgraphField<Vec<MsgraphRecipient>>,
#[serde(default, skip_serializing_if = "MsgraphField::is_unset")]
#[cfg_attr(feature = "schemars", schemars(with = "Option<Vec<MsgraphRecipient>>"))]
pub cc_recipients: MsgraphField<Vec<MsgraphRecipient>>,
#[serde(default, skip_serializing_if = "MsgraphField::is_unset")]
#[cfg_attr(feature = "schemars", schemars(with = "Option<Vec<MsgraphRecipient>>"))]
pub bcc_recipients: MsgraphField<Vec<MsgraphRecipient>>,
#[serde(default, skip_serializing_if = "MsgraphField::is_unset")]
#[cfg_attr(feature = "schemars", schemars(with = "Option<Vec<MsgraphRecipient>>"))]
pub reply_to: MsgraphField<Vec<MsgraphRecipient>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub received_date_time: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sent_date_time: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_read: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub is_draft: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub has_attachments: Option<bool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub internet_message_id: Option<String>,
#[serde(
default,
deserialize_with = "null_as_empty",
skip_serializing_if = "Vec::is_empty"
)]
pub internet_message_headers: Vec<MsgraphInternetMessageHeader>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub importance: Option<MsgraphImportance>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub flag: Option<MsgraphFollowupFlag>,
#[serde(default, skip_serializing_if = "MsgraphField::is_unset")]
#[cfg_attr(feature = "schemars", schemars(with = "Option<Vec<String>>"))]
pub categories: MsgraphField<Vec<String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub parent_folder_id: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub conversation_id: Option<String>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub single_value_extended_properties: Vec<MsgraphSingleValueExtendedProperty>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct MsgraphRecipient {
pub email_address: MsgraphEmailAddress,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct MsgraphEmailAddress {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub address: Option<String>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct MsgraphItemBody {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub content_type: Option<MsgraphBodyType>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub content: Option<String>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct MsgraphFollowupFlag {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub flag_status: Option<MsgraphFlagStatus>,
}
#[derive(Debug, Clone, Default, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub struct MsgraphInternetMessageHeader {
#[serde(default)]
pub name: String,
#[serde(default)]
pub value: String,
}
#[derive(Debug, Clone, Copy, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum MsgraphBodyType {
Text,
Html,
}
#[derive(Debug, Clone, Copy, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase")]
pub enum MsgraphFlagStatus {
NotFlagged,
Complete,
Flagged,
}
#[derive(Debug, Clone, Copy, Deserialize, Serialize, Eq, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename_all = "lowercase")]
pub enum MsgraphImportance {
Low,
Normal,
High,
}
fn null_as_empty<'de, D, T>(deserializer: D) -> Result<Vec<T>, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de>,
{
Ok(Option::<Vec<T>>::deserialize(deserializer)?.unwrap_or_default())
}
#[cfg(test)]
mod tests {
use alloc::vec::Vec;
use crate::v1::{field::MsgraphField, rest::users::messages::MsgraphMessage};
#[test]
fn an_update_can_clear_the_categories() {
let clear = MsgraphMessage {
categories: MsgraphField::Set(Vec::new()),
..Default::default()
};
let keep = MsgraphMessage::default();
assert_eq!(
serde_json::to_string(&clear).unwrap(),
r#"{"categories":[]}"#
);
assert_eq!(serde_json::to_string(&keep).unwrap(), "{}");
}
}