1use serde::Serialize;
2
3use crate::{MessageFormat, NotifyError, Priority, provider::StoredAttachment};
4
5#[derive(Debug, Serialize)]
6pub struct SendOutput {
7 pub ok: bool,
8 pub sent: bool,
9 pub dry_run: bool,
10 pub results: Vec<SendResultOutput>,
11}
12
13#[derive(Debug, Serialize)]
14pub struct SendResultOutput {
15 pub ok: bool,
16 pub channel: String,
17 #[serde(rename = "type")]
18 pub channel_type: String,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub id: Option<String>,
21 pub sent: bool,
22 pub dry_run: bool,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub attachments: Option<Vec<StoredAttachment>>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub error: Option<ErrorBody>,
27}
28
29#[derive(Debug, Serialize)]
30pub struct DryRunOutput {
31 pub ok: bool,
32 pub dry_run: bool,
33 pub sent: bool,
34 pub results: Vec<DryRunResultOutput>,
35}
36
37#[derive(Debug, Serialize)]
38pub struct DryRunResultOutput {
39 pub ok: bool,
40 pub channel: String,
41 #[serde(rename = "type")]
42 pub channel_type: String,
43 pub sent: bool,
44 pub dry_run: bool,
45 pub message: DryRunMessage,
46 pub attachments: Vec<DryRunAttachment>,
47}
48
49#[derive(Debug, Serialize)]
50pub struct DryRunMessage {
51 pub title: String,
52 pub body: Option<String>,
53 pub format: MessageFormat,
54 pub priority: Priority,
55 pub tags: Vec<String>,
56}
57
58#[derive(Debug, Serialize)]
59pub struct DryRunAttachment {
60 pub path: String,
61}
62
63#[derive(Debug, Serialize)]
64pub struct ErrorOutput {
65 pub ok: bool,
66 pub error: ErrorBody,
67}
68
69#[derive(Debug, Serialize)]
70pub struct ErrorBody {
71 pub code: String,
72 pub message: String,
73}
74
75impl From<&NotifyError> for ErrorOutput {
76 fn from(error: &NotifyError) -> Self {
77 Self {
78 ok: false,
79 error: ErrorBody {
80 code: error.code().to_string(),
81 message: error.to_string(),
82 },
83 }
84 }
85}