1use serde::Serialize;
5use serde_json::Value;
6
7use crate::block::{Block, to_value};
8
9#[derive(Debug, Clone, Serialize)]
11#[serde(rename_all = "camelCase")]
12pub struct WindowsSnapshot {
13 pub operable_window_ids: Vec<String>,
15 pub windows: Vec<WindowOut>,
17}
18
19#[derive(Debug, Clone, Serialize)]
21#[serde(rename_all = "camelCase")]
22pub struct WindowOut {
23 pub id: String,
25 pub title: String,
27 pub modal: bool,
29 pub owner_id: Option<String>,
31 pub version: i64,
33 #[serde(skip_serializing_if = "Option::is_none")]
35 pub summary: Option<String>,
36 pub blocks: Vec<Block>,
38}
39
40#[derive(Debug, Clone, Default, Serialize)]
44#[serde(rename_all = "camelCase")]
45pub struct Outcome {
46 #[serde(skip_serializing_if = "Option::is_none")]
48 pub message: Option<String>,
49 #[serde(skip_serializing_if = "Vec::is_empty")]
51 pub opened_window_ids: Vec<String>,
52 #[serde(skip_serializing_if = "Option::is_none")]
55 pub result: Option<Value>,
56}
57
58impl Outcome {
59 pub fn message(msg: impl Into<String>) -> Self {
61 Outcome {
62 message: Some(msg.into()),
63 opened_window_ids: Vec::new(),
64 result: None,
65 }
66 }
67
68 pub fn opened<I, S>(mut self, ids: I) -> Self
71 where
72 I: IntoIterator<Item = S>,
73 S: Into<String>,
74 {
75 self.opened_window_ids = ids.into_iter().map(Into::into).collect();
76 self
77 }
78
79 pub fn with(mut self, result: impl Serialize) -> Self {
82 self.result = Some(to_value(result));
83 self
84 }
85
86 pub(crate) fn to_structured(&self) -> Value {
88 to_value(self)
89 }
90
91 pub(crate) fn text_mirror(&self) -> String {
93 self.message.clone().unwrap_or_default()
94 }
95}
96
97impl From<&str> for Outcome {
98 fn from(s: &str) -> Self {
99 Outcome::message(s)
100 }
101}
102
103impl From<String> for Outcome {
104 fn from(s: String) -> Self {
105 Outcome::message(s)
106 }
107}
108
109impl From<()> for Outcome {
110 fn from(_: ()) -> Self {
111 Outcome::default()
112 }
113}