use poem_openapi::{Object, Union};
use serde::{Deserialize, Serialize};
use crate::{
model::viewobject::{MessageContent, MessageVO as CoreMessageVO},
poem_openapi::model::viewobject::{OApiChatVO, OApiNull},
};
#[derive(Debug, Clone, Serialize, Deserialize, Object)]
pub struct OApiMessageVO {
pub chat: OApiChatVO,
pub id: String,
pub user_key: String,
pub parent_id: Option<String>,
pub parent_user_key: Option<String>,
pub content: OApiMessageContent,
pub receiver_keys: Vec<String>,
pub create_time: i64,
}
impl From<CoreMessageVO> for OApiMessageVO {
fn from(value: CoreMessageVO) -> Self {
Self {
chat: value.chat.into(),
id: value.id,
user_key: value.user_key,
parent_id: value.parent_id,
parent_user_key: value.parent_user_key,
content: value.content.into(),
receiver_keys: value.receiver_keys,
create_time: value.create_time,
}
}
}
impl Into<CoreMessageVO> for OApiMessageVO {
fn into(self) -> CoreMessageVO {
CoreMessageVO {
chat: self.chat.into(),
id: self.id,
user_key: self.user_key,
parent_id: self.parent_id,
parent_user_key: self.parent_user_key,
content: self.content.into(),
receiver_keys: self.receiver_keys,
create_time: self.create_time,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Union)]
pub enum OApiMessageContent {
Text(String),
Image(String),
Video(String),
File(String),
Check(OApiNull),
}
impl From<MessageContent> for OApiMessageContent {
fn from(value: MessageContent) -> Self {
match value {
MessageContent::Text(s) => Self::Text(s),
MessageContent::Image(s) => Self::Image(s),
MessageContent::Video(s) => Self::Video(s),
MessageContent::File(s) => Self::File(s),
MessageContent::Check(n) => Self::Check(n.into()),
}
}
}
impl Into<MessageContent> for OApiMessageContent {
fn into(self) -> MessageContent {
match self {
OApiMessageContent::Text(s) => MessageContent::Text(s),
OApiMessageContent::Image(s) => MessageContent::Image(s),
OApiMessageContent::Video(s) => MessageContent::Video(s),
OApiMessageContent::File(s) => MessageContent::File(s),
OApiMessageContent::Check(n) => MessageContent::Check(n.into()),
}
}
}