fcm_rs/models.rs
1//! Data models for FCM messages, requests, and responses.
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5/// Represents an FCM message to be sent.
6#[derive(Serialize, Deserialize, Debug)]
7pub struct Message {
8 /// Registration token of the target device or the topic name for subscription.
9 pub token: Option<String>,
10 /// Notification payload.
11 pub notification: Option<Notification>,
12 /// Custom data payload.
13 pub data: Option<serde_json::Value>,
14 // Add other FCM message fields as needed (e.g., condition, priority)
15}
16
17/// Represents a notification payload within an FCM message.
18#[derive(Serialize, Deserialize, Debug)]
19pub struct Notification {
20 /// Title of the notification.
21 pub title: Option<String>,
22 /// Body text of the notification.
23 pub body: Option<String>,
24 // Add other notification fields (e.g., icon, click_action)
25}
26
27/// Represents a request to send an FCM message.
28#[derive(Serialize, Debug)]
29pub struct FcmSendRequest {
30 /// The FCM message to send.
31 pub message: Message,
32 // Add other request parameters (e.g., validate_only: bool) if needed
33}
34
35/// Represents the result of a sent FCM message.
36#[derive(Deserialize)]
37#[serde(untagged)]
38pub enum FcmSendResult {
39 /// A successful response from FCM.
40 Success(FcmSuccessResponse),
41 /// An error response from FCM.
42 Error(FcmErrorResponse),
43}
44
45/// Represents a successful response from the FCM API after sending a message.
46#[derive(Deserialize, Debug)]
47pub struct FcmSuccessResponse {
48 /// Message ID if the message was successfully processed
49 pub name: String,
50}
51
52/// Represents an error response from the FCM API after sending a message.
53#[derive(Serialize, Deserialize, Debug)]
54pub struct FcmErrorResponse {
55 /// Error if the message was unsuccessfully processed.
56 pub error: ErrorResponse,
57}
58
59/// Contains the details of an error response from FCM.
60/// Visit the [FCM Documentation](https://firebase.google.com/docs/cloud-messaging/send-message#rest) for details on the possible errors the API can respond with.
61#[derive(Serialize, Deserialize, Debug)]
62pub struct ErrorResponse {
63 /// The error code.
64 pub code: usize,
65 /// The error message.
66 pub message: String,
67 /// The error status
68 pub status: String,
69 /// Additional details about the error.
70 pub details: Vec<Value>,
71}