use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NotificationResponse {
pub status: String,
pub message: String,
}
impl NotificationResponse {
pub fn is_success(&self) -> bool {
self.status == "success"
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RateLimitInfo {
pub limit: u32,
pub remaining: u32,
pub reset: u64,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NotifAIResponse {
pub status: String,
pub notification: NotifAINotification,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct NotifAINotification {
pub title: String,
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "type")]
pub notification_type: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ErrorResponse {
pub status: String,
pub error: ErrorDetail,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ErrorDetail {
#[serde(rename = "type")]
pub error_type: String,
pub code: String,
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub param: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_success() {
let response = NotificationResponse {
status: "success".to_string(),
message: "Notification sent".to_string(),
};
assert!(response.is_success());
}
#[test]
fn test_is_not_success() {
let response = NotificationResponse {
status: "error".to_string(),
message: "Failed".to_string(),
};
assert!(!response.is_success());
}
#[test]
fn test_json_serialization() {
let response = NotificationResponse {
status: "success".to_string(),
message: "Notification sent".to_string(),
};
let json = serde_json::to_string(&response).unwrap();
assert!(json.contains("success"));
assert!(json.contains("Notification sent"));
}
#[test]
fn test_json_deserialization() {
let json = r#"{"status":"success","message":"Notification sent"}"#;
let response: NotificationResponse = serde_json::from_str(json).unwrap();
assert_eq!(response.status, "success");
assert_eq!(response.message, "Notification sent");
assert!(response.is_success());
}
}