1use crate::api::types::LemmaType;
4use crate::api::value::RuleResultValue;
5use crate::literals::Value;
6use crate::parsing::ast::DateTimeValue;
7use crate::parsing::source::SourceType;
8use crate::planning::execution_plan::{
9 Show as DomainShow, ShowData as DomainShowData, ShowVersion as DomainShowVersion,
10};
11use indexmap::IndexMap;
12use serde::{Deserialize, Serialize};
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15pub struct ShowData {
16 #[serde(rename = "type")]
17 pub lemma_type: LemmaType,
18 #[serde(skip_serializing_if = "Option::is_none", default)]
19 pub fill: Option<RuleResultValue>,
20 #[serde(skip_serializing_if = "Option::is_none", default)]
21 pub suggestion: Option<RuleResultValue>,
22 pub needed_by_rules: Vec<String>,
23}
24
25impl From<&DomainShowData> for ShowData {
26 fn from(data: &DomainShowData) -> Self {
27 Self {
28 lemma_type: LemmaType::from(&data.lemma_type),
29 fill: data.fill.as_ref().map(RuleResultValue::from),
30 suggestion: data.suggestion.as_ref().map(RuleResultValue::from),
31 needed_by_rules: data.needed_by_rules.clone(),
32 }
33 }
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
37pub struct ShowVersion {
38 #[serde(skip_serializing_if = "Option::is_none", default)]
39 pub effective_from: Option<DateTimeValue>,
40 #[serde(skip_serializing_if = "Option::is_none", default)]
41 pub effective_to: Option<DateTimeValue>,
42}
43
44impl From<&DomainShowVersion> for ShowVersion {
45 fn from(version: &DomainShowVersion) -> Self {
46 Self {
47 effective_from: version.effective_from.clone(),
48 effective_to: version.effective_to.clone(),
49 }
50 }
51}
52
53#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
54pub struct Show {
55 pub spec: String,
56 #[serde(skip_serializing_if = "Option::is_none", default)]
57 pub commentary: Option<String>,
58 #[serde(skip_serializing_if = "Option::is_none", default)]
59 pub effective_from: Option<DateTimeValue>,
60 #[serde(skip_serializing_if = "Option::is_none", default)]
61 pub effective_to: Option<DateTimeValue>,
62 #[serde(skip_serializing_if = "Vec::is_empty", default)]
63 pub versions: Vec<ShowVersion>,
64 pub start_line: usize,
65 #[serde(skip_serializing_if = "Option::is_none", default)]
66 pub source_type: Option<SourceType>,
67 pub data: IndexMap<String, ShowData>,
68 pub rules: IndexMap<String, LemmaType>,
69 pub meta: IndexMap<String, Value>,
70}
71
72impl From<&DomainShow> for Show {
73 fn from(show: &DomainShow) -> Self {
74 Self {
75 spec: show.spec.clone(),
76 commentary: show.commentary.clone(),
77 effective_from: show.effective_from.clone(),
78 effective_to: show.effective_to.clone(),
79 versions: show.versions.iter().map(ShowVersion::from).collect(),
80 start_line: show.start_line,
81 source_type: show.source_type.clone(),
82 data: show
83 .data
84 .iter()
85 .map(|(name, data)| (name.clone(), ShowData::from(data)))
86 .collect(),
87 rules: show
88 .rules
89 .iter()
90 .map(|(name, lemma_type)| (name.clone(), LemmaType::from(lemma_type)))
91 .collect(),
92 meta: show.meta.clone(),
93 }
94 }
95}