zulip_api/message/push_device.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// Represents the details of a push device with the push account ID as the key.
6///
7/// Modified from `openapi-generator-cli` output:
8///
9/// ```shell,no_build,no_run
10/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
11/// ```
12///
13/// ```text
14/// /*
15/// * Zulip REST API
16/// *
17/// * Powerful open source group chat
18/// *
19/// * The version of the OpenAPI document: 1.0.0
20/// *
21/// * Generated by: https://openapi-generator.tech
22/// */
23/// ```
24///
25/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
26///
27/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
28#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
29pub struct PushDevice {
30 #[serde(skip_serializing_if = "Option::is_none")]
31 status: Option<PushDeviceStatus>,
32 #[serde(skip_serializing_if = "Option::is_none")]
33 error_code: Option<String>,
34}
35
36impl PushDevice {
37 /// Creates a new [PushDevice].
38 pub fn new() -> Self {
39 Self {
40 status: None,
41 error_code: None,
42 }
43 }
44}
45
46field_access! {
47 PushDevice {
48 /// The push account's registration status.
49 status: option { PushDeviceStatus },
50 }
51}
52
53field_access! {
54 PushDevice {
55 /// If the status is `\"failed\"`, a [Zulip API error code](https://zulip.com/api/rest-error-handling) indicating the type of failure that occurred.
56 ///
57 /// The following error codes have recommended client behavior:
58 ///
59 /// - `\"INVALID_BOUNCER_PUBLIC_KEY\"`: Inform the user to update app.
60 /// - `\"REQUEST_EXPIRED`: Retry with a fresh payload.
61 error_code: option_cow_deref { str, String },
62 }
63}
64
65impl_default!(PushDevice);
66impl_display!(PushDevice);
67
68/// Represents the push account's registration status.
69///
70/// Either:
71///
72/// - `\"active\"`
73/// - `\"pending\"`
74/// - `\"failed\"`
75#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
76#[serde(rename_all = "snake_case")]
77pub enum PushDeviceStatus {
78 Active,
79 Pending,
80 Failed,
81}
82
83impl PushDeviceStatus {
84 /// Creates a new [PushDeviceStatus].
85 pub const fn new() -> Self {
86 Self::Active
87 }
88}
89
90impl_default!(PushDeviceStatus);
91impl_display!(PushDeviceStatus);