1use serde::Deserialize;
2
3use crate::advice::Advice;
4
5#[derive(Deserialize, PartialEq, Debug)]
8#[serde(rename_all = "camelCase")]
9pub struct BasicResponse {
10 pub channel: String,
11 pub successful: bool,
12 pub error: Option<String>,
13 pub advice: Option<Advice>,
14 pub ext: Option<serde_json::Value>,
15 pub client_id: Option<String>,
16 pub id: Option<String>,
17}
18
19#[derive(Deserialize, PartialEq, Clone, Debug)]
21#[serde(rename_all = "camelCase")]
22pub struct HandshakeResponse {
23 pub channel: String,
24 pub successful: bool,
25 pub version: String,
26 pub minimum_version: Option<String>,
27 pub client_id: String,
28 pub supported_connection_types: Vec<String>,
29 pub advice: Option<Advice>,
30 pub ext: Option<serde_json::Value>,
31 pub id: Option<String>,
32 pub auth_successful: Option<bool>,
33}
34
35#[derive(Deserialize, PartialEq, Clone, Debug)]
38#[serde(rename_all = "camelCase")]
39pub struct ErroredResponse {
40 pub channel: String,
41 pub successful: bool,
42 pub error: String,
43 pub client_id: Option<String>,
44 pub subscription: Option<String>,
45 pub advice: Option<Advice>,
46 pub ext: Option<serde_json::Value>,
47 pub id: Option<String>,
48}
49
50#[derive(Deserialize, PartialEq, Clone, Debug)]
52#[serde(rename_all = "camelCase")]
53pub struct PublishResponse {
54 pub channel: String,
55 pub client_id: String,
56 pub successful: bool,
57 pub error: Option<String>,
58 pub advice: Option<Advice>,
59 pub ext: Option<serde_json::Value>,
60 pub data: serde_json::Value,
61 pub id: Option<String>,
62}
63
64#[derive(Deserialize, PartialEq, Clone, Debug)]
67#[serde(rename_all = "camelCase")]
68pub struct DeliveryResponse {
69 pub channel: String,
70 pub advice: Option<Advice>,
71 pub data: serde_json::Value,
72 pub ext: Option<serde_json::Value>,
73 pub id: Option<String>,
74}
75
76#[derive(Deserialize, PartialEq, Debug)]
78#[serde(untagged)]
79pub enum Response {
80 Handshake(HandshakeResponse),
82 Publish(PublishResponse),
84 Delivery(DeliveryResponse),
87 Basic(BasicResponse),
90}
91
92impl Response {
93 pub fn advice(&self) -> Option<Advice> {
95 match self {
96 Response::Handshake(resp) => resp.advice.clone(),
97 Response::Publish(resp) => resp.advice.clone(),
98 Response::Delivery(resp) => resp.advice.clone(),
99 Response::Basic(resp) => resp.advice.clone(),
100 }
101 }
102}