use serde::{Deserialize, Serialize};
use crate::JsonObject;
use crate::event::BaseEvent;
use crate::ids::MessageId;
use crate::patch::PatchOperation;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct ActivitySnapshotEvent {
#[serde(flatten)]
pub base: BaseEvent,
pub message_id: MessageId,
pub activity_type: String,
#[cfg_attr(
feature = "schemars",
schemars(with = "std::collections::BTreeMap<String, serde_json::Value>")
)]
#[cfg_attr(feature = "utoipa", schema(value_type = Object))]
pub content: JsonObject,
#[serde(default = "default_replace")]
pub replace: bool,
}
const fn default_replace() -> bool {
true
}
impl Default for ActivitySnapshotEvent {
fn default() -> Self {
Self {
base: BaseEvent::default(),
message_id: MessageId::default(),
activity_type: String::new(),
content: JsonObject::new(),
replace: default_replace(),
}
}
}
impl ActivitySnapshotEvent {
pub fn new(
message_id: impl Into<MessageId>,
activity_type: impl Into<String>,
content: JsonObject,
) -> Self {
Self {
base: BaseEvent::default(),
message_id: message_id.into(),
activity_type: activity_type.into(),
content,
replace: true,
}
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct ActivityDeltaEvent {
#[serde(flatten)]
pub base: BaseEvent,
pub message_id: MessageId,
pub activity_type: String,
pub patch: Vec<PatchOperation>,
}
impl ActivityDeltaEvent {
pub fn new(
message_id: impl Into<MessageId>,
activity_type: impl Into<String>,
patch: impl Into<Vec<PatchOperation>>,
) -> Self {
Self {
base: BaseEvent::default(),
message_id: message_id.into(),
activity_type: activity_type.into(),
patch: patch.into(),
}
}
}