use serde::{Deserialize, Serialize};
use super::{
command::{CommandError, CommandResponse, WrappedCommand},
event::MEvent,
query::{QueryError, QueryResponse, QueryWindowUpdate, WrappedQuery},
report::{ReportError, ReportResponse, WrappedReport},
view::{ViewError, ViewResponse, ViewWindowUpdate, WrappedView},
};
pub const WS_EVENT_COMMAND: &str = "ws:m:command";
#[derive(Debug, Clone, Serialize, Deserialize, ts_rs::TS)]
#[ts(export)]
pub struct CancelSubscription {
pub tx: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, ts_rs::TS)]
#[ts(export)]
pub struct PingData {
pub id: String,
pub timestamp: i64,
}
#[derive(Debug)]
pub struct MessageEventRegistration {
pub variant_name: &'static str,
pub event_value: &'static str,
}
inventory::collect!(MessageEventRegistration);
#[derive(Debug, Clone, Serialize, Deserialize, ts_rs::TS, myko_macros::MessageEvents)]
#[ts(export)]
#[serde(tag = "event", content = "data")]
pub enum MykoMessage {
#[serde(rename = "ws:m:query")]
Query(WrappedQuery),
#[serde(rename = "ws:m:query-response")]
QueryResponse(#[ts(type = "any")] QueryResponse),
#[serde(rename = "ws:m:query-cancel")]
QueryCancel(CancelSubscription),
#[serde(rename = "ws:m:query-window")]
QueryWindow(QueryWindowUpdate),
#[serde(rename = "ws:m:view")]
View(WrappedView),
#[serde(rename = "ws:m:view-response")]
ViewResponse(#[ts(type = "any")] ViewResponse),
#[serde(rename = "ws:m:view-cancel")]
ViewCancel(CancelSubscription),
#[serde(rename = "ws:m:view-window")]
ViewWindow(ViewWindowUpdate),
#[serde(rename = "ws:m:report")]
Report(WrappedReport),
#[serde(rename = "ws:m:report-response")]
ReportResponse(ReportResponse),
#[serde(rename = "ws:m:report-cancel")]
ReportCancel(CancelSubscription),
#[serde(rename = "ws:m:report-error")]
ReportError(ReportError),
#[serde(rename = "ws:m:query-error")]
QueryError(QueryError),
#[serde(rename = "ws:m:view-error")]
ViewError(ViewError),
#[serde(rename = "ws:m:event")]
Event(MEvent),
#[serde(rename = "ws:m:event-batch")]
EventBatch(Vec<MEvent>),
#[serde(rename = "ws:m:command")]
Command(WrappedCommand),
#[serde(rename = "ws:m:command-response")]
CommandResponse(CommandResponse),
#[serde(rename = "ws:m:command-error")]
CommandError(CommandError),
#[serde(rename = "ws:m:ping")]
Ping(PingData),
#[serde(rename = "ws:m:benchmark")]
Benchmark(serde_json::Value),
#[serde(rename = "ws:m:protocol-switch")]
ProtocolSwitch { protocol: String },
}