1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8pub enum AttachmentKind {
9 Image,
11 File,
13 Video,
15 Audio,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct Attachment {
22 pub name: Option<String>,
24 pub mime_type: Option<String>,
26 pub size: Option<u64>,
28 pub url: Option<String>,
30 #[serde(skip)]
32 pub data: Option<bytes::Bytes>,
33 pub kind: AttachmentKind,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct FileUpload {
40 pub filename: String,
42 pub mime_type: Option<String>,
44 #[serde(skip)]
46 pub data: bytes::Bytes,
47}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn attachment_kind_roundtrip() {
55 let json = serde_json::to_string(&AttachmentKind::Image).expect("serialize");
56 let back: AttachmentKind = serde_json::from_str(&json).expect("deserialize");
57 assert_eq!(back, AttachmentKind::Image);
58 }
59
60 #[test]
61 fn attachment_debug() {
62 let att = Attachment {
63 name: Some("photo.png".into()),
64 mime_type: Some("image/png".into()),
65 size: Some(1024),
66 url: None,
67 data: None,
68 kind: AttachmentKind::Image,
69 };
70 let dbg = format!("{att:?}");
71 assert!(dbg.contains("photo.png"));
72 }
73
74 #[test]
75 fn file_upload_debug() {
76 let fu = FileUpload {
77 filename: "report.pdf".into(),
78 mime_type: Some("application/pdf".into()),
79 data: bytes::Bytes::from_static(b"fake"),
80 };
81 let dbg = format!("{fu:?}");
82 assert!(dbg.contains("report.pdf"));
83 }
84}