edda_types/combat/
protocol.rs1use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7use super::{CombatCommand, CombatEvent, CombatState, CombatStatus};
8
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
15pub struct CommandEnvelope {
16 pub command_id: Uuid,
17 #[serde(default, skip_serializing_if = "Option::is_none")]
19 pub actor: Option<String>,
20 pub command: CombatCommand,
21}
22
23impl CommandEnvelope {
24 pub fn new(command: CombatCommand) -> Self {
26 Self {
27 command_id: Uuid::new_v4(),
28 actor: None,
29 command,
30 }
31 }
32
33 #[must_use]
36 pub fn by(mut self, actor: impl Into<String>) -> Self {
37 self.actor = Some(actor.into());
38 self
39 }
40}
41
42#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
45pub struct LoggedEvent {
46 pub seq: u64,
48 pub command_id: Option<Uuid>,
50 #[serde(default, skip_serializing_if = "Option::is_none")]
51 pub actor: Option<String>,
52 pub at: DateTime<Utc>,
53 pub event: CombatEvent,
54}
55
56#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
58#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
59pub struct CombatSnapshot {
60 pub id: Uuid,
61 pub seq: u64,
62 pub state: CombatState,
63}
64
65#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
67#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
68pub struct CombatSummary {
69 pub id: Uuid,
70 pub campaign: String,
71 pub name: String,
72 pub status: CombatStatus,
73 pub round: u32,
74 pub created_at: DateTime<Utc>,
75 pub updated_at: DateTime<Utc>,
77}
78
79#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
81#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
82#[serde(tag = "type", content = "data", rename_all = "snake_case")]
83pub enum ServerMessage {
84 Snapshot(CombatSnapshot),
86 Event(LoggedEvent),
88 Rejected { command_id: Uuid, error: String },
90 AlreadyApplied { command_id: Uuid },
93}
94
95#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
97#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
98#[serde(tag = "type", content = "data", rename_all = "snake_case")]
99pub enum ClientMessage {
100 Command(CommandEnvelope),
101}