use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum AttachmentKind {
Image,
File,
Video,
Audio,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Attachment {
pub name: Option<String>,
pub mime_type: Option<String>,
pub size: Option<u64>,
pub url: Option<String>,
#[serde(skip)]
pub data: Option<bytes::Bytes>,
pub kind: AttachmentKind,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileUpload {
pub filename: String,
pub mime_type: Option<String>,
#[serde(skip)]
pub data: bytes::Bytes,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn attachment_kind_roundtrip() {
let json = serde_json::to_string(&AttachmentKind::Image).expect("serialize");
let back: AttachmentKind = serde_json::from_str(&json).expect("deserialize");
assert_eq!(back, AttachmentKind::Image);
}
#[test]
fn attachment_debug() {
let att = Attachment {
name: Some("photo.png".into()),
mime_type: Some("image/png".into()),
size: Some(1024),
url: None,
data: None,
kind: AttachmentKind::Image,
};
let dbg = format!("{att:?}");
assert!(dbg.contains("photo.png"));
}
#[test]
fn file_upload_debug() {
let fu = FileUpload {
filename: "report.pdf".into(),
mime_type: Some("application/pdf".into()),
data: bytes::Bytes::from_static(b"fake"),
};
let dbg = format!("{fu:?}");
assert!(dbg.contains("report.pdf"));
}
}