use serde::{Deserialize, Serialize};
use crate::response::BaseResponse;
use crate::{field_access, impl_default, impl_display, impl_response};
mod message_history;
pub use message_history::MessageHistory;
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct Response {
#[serde(flatten)]
base: BaseResponse,
#[serde(skip_serializing_if = "Option::is_none")]
message_history: Option<Vec<MessageHistory>>,
}
impl Response {
pub const fn new() -> Self {
Self {
base: BaseResponse::new(),
message_history: None,
}
}
}
field_access! {
Response {
message_history: option_cow_deref { [MessageHistory], Vec<MessageHistory> },
}
}
impl_default!(Response);
impl_display!(Response);
impl_response!(Response, base);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_response() {
let message_history = [MessageHistory::new()];
let response = Response::new().with_message_history(message_history.as_ref());
let response_json = response.to_string();
assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
assert_eq!(
serde_json::from_str::<Response>(&response_json).unwrap(),
response
);
assert_eq!(response.message_history(), Some(message_history.as_ref()));
}
}