use std::collections::HashMap;
use serde::{Deserialize, Serialize};
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum DreamType {
#[serde(rename = "omni")]
Omni,
#[serde(other, rename = "unknown")]
Unknown,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, bon::Builder)]
#[non_exhaustive]
#[builder(derive(Debug), on(String, into))]
#[builder(finish_fn = build)]
pub struct ScheduleDreamRequest {
pub observer: String,
#[builder(default = DreamType::Omni)]
pub dream_type: DreamType,
#[serde(skip_serializing_if = "Option::is_none")]
pub observed: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub session_id: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SessionQueueStatus {
#[serde(skip_serializing_if = "Option::is_none")]
pub session_id: Option<String>,
pub total_work_units: u64,
pub completed_work_units: u64,
pub in_progress_work_units: u64,
pub pending_work_units: u64,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct QueueStatus {
pub total_work_units: u64,
pub completed_work_units: u64,
pub in_progress_work_units: u64,
pub pending_work_units: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub sessions: Option<HashMap<String, SessionQueueStatus>>,
}
#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic, missing_docs)]
mod tests {
use std::collections::HashSet;
use serde_json::json;
use super::*;
#[test]
fn dream_type_unknown_catches_future_variants() {
let got: DreamType = serde_json::from_value(json!("some_future_dream")).unwrap();
assert_eq!(got, DreamType::Unknown);
}
#[test]
fn dream_type_omni_roundtrips_exact_wire_string() {
assert_eq!(serde_json::to_string(&DreamType::Omni).unwrap(), "\"omni\"");
let got: DreamType = serde_json::from_value(json!("omni")).unwrap();
assert_eq!(got, DreamType::Omni);
}
#[test]
fn dream_type_is_hashable() {
let mut set = HashSet::new();
set.insert(DreamType::Omni);
set.insert(DreamType::Unknown);
set.insert(DreamType::Omni); assert_eq!(set.len(), 2);
}
}