1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5use super::CommandType;
6
7#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
8pub struct CommandResult {
9 pub success: bool,
10 pub command_type: CommandType,
11 #[serde(flatten, skip_serializing_if = "Option::is_none")]
12 pub data: Option<CommandData>,
13 #[serde(default, skip_serializing_if = "Option::is_none")]
14 pub error: Option<String>,
15 #[serde(default, skip_serializing_if = "Option::is_none")]
16 pub debug: Option<serde_json::Value>,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
20#[serde(tag = "content_type", content = "data", rename_all = "snake_case")]
21pub enum CommandData {
22 Markdown(String),
23 Html(String),
24 String(String),
25 Data(Value),
26}
27
28impl CommandResult {
29 pub fn content(&self) -> Value {
30 match &self.data {
31 Some(CommandData::Markdown(s))
32 | Some(CommandData::Html(s))
33 | Some(CommandData::String(s)) => Value::String(s.to_string()),
34 Some(CommandData::Data(value)) => value.clone(),
35 None => Value::Null,
36 }
37 }
38}