1use std::collections::HashMap;
4
5use serde::{Deserialize, Serialize};
6
7#[non_exhaustive]
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub enum DreamType {
11 #[serde(rename = "omni")]
13 Omni,
14 #[serde(other, rename = "unknown")]
16 Unknown,
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, bon::Builder)]
23#[non_exhaustive]
24#[builder(derive(Debug), on(String, into))]
25#[builder(finish_fn = build)]
26pub struct ScheduleDreamRequest {
27 pub observer: String,
29 #[builder(default = DreamType::Omni)]
31 pub dream_type: DreamType,
32 #[serde(skip_serializing_if = "Option::is_none")]
34 pub observed: Option<String>,
35 #[serde(skip_serializing_if = "Option::is_none")]
37 pub session_id: Option<String>,
38}
39
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
44#[non_exhaustive]
45pub struct SessionQueueStatus {
46 #[serde(skip_serializing_if = "Option::is_none")]
48 pub session_id: Option<String>,
49 pub total_work_units: u64,
51 pub completed_work_units: u64,
53 pub in_progress_work_units: u64,
55 pub pending_work_units: u64,
57}
58
59#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
66#[non_exhaustive]
67pub struct QueueStatus {
68 pub total_work_units: u64,
70 pub completed_work_units: u64,
72 pub in_progress_work_units: u64,
74 pub pending_work_units: u64,
76 #[serde(skip_serializing_if = "Option::is_none")]
78 pub sessions: Option<HashMap<String, SessionQueueStatus>>,
79}
80
81#[cfg(test)]
82#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic, missing_docs)]
83mod tests {
84 use std::collections::HashSet;
85
86 use serde_json::json;
87
88 use super::*;
89
90 #[test]
91 fn dream_type_unknown_catches_future_variants() {
92 let got: DreamType = serde_json::from_value(json!("some_future_dream")).unwrap();
94 assert_eq!(got, DreamType::Unknown);
95 }
96
97 #[test]
98 fn dream_type_omni_roundtrips_exact_wire_string() {
99 assert_eq!(serde_json::to_string(&DreamType::Omni).unwrap(), "\"omni\"");
101 let got: DreamType = serde_json::from_value(json!("omni")).unwrap();
102 assert_eq!(got, DreamType::Omni);
103 }
104
105 #[test]
106 fn dream_type_is_hashable() {
107 let mut set = HashSet::new();
109 set.insert(DreamType::Omni);
110 set.insert(DreamType::Unknown);
111 set.insert(DreamType::Omni); assert_eq!(set.len(), 2);
113 }
114}