mockforge_world_state/
query.rs1use crate::model::{NodeType, StateEdge, StateLayer, StateNode};
7use serde::{Deserialize, Serialize};
8use std::collections::HashSet;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct WorldStateQuery {
13 #[serde(default)]
15 pub node_types: Option<HashSet<NodeType>>,
16 #[serde(default)]
18 pub layers: Option<HashSet<StateLayer>>,
19 #[serde(default)]
21 pub node_ids: Option<HashSet<String>>,
22 #[serde(default)]
24 pub relationship_types: Option<HashSet<String>>,
25 #[serde(default = "default_true")]
27 pub include_edges: bool,
28 #[serde(default)]
30 pub max_depth: Option<usize>,
31}
32
33fn default_true() -> bool {
34 true
35}
36
37impl Default for WorldStateQuery {
38 fn default() -> Self {
39 Self {
40 node_types: None,
41 layers: None,
42 node_ids: None,
43 relationship_types: None,
44 include_edges: true,
45 max_depth: None,
46 }
47 }
48}
49
50impl WorldStateQuery {
51 pub fn new() -> Self {
53 Self::default()
54 }
55
56 pub fn with_node_types(mut self, types: HashSet<NodeType>) -> Self {
58 self.node_types = Some(types);
59 self
60 }
61
62 pub fn with_layers(mut self, layers: HashSet<StateLayer>) -> Self {
64 self.layers = Some(layers);
65 self
66 }
67
68 pub fn with_node_ids(mut self, ids: HashSet<String>) -> Self {
70 self.node_ids = Some(ids);
71 self
72 }
73
74 pub fn with_relationship_types(mut self, types: HashSet<String>) -> Self {
76 self.relationship_types = Some(types);
77 self
78 }
79
80 pub fn include_edges(mut self, include: bool) -> Self {
82 self.include_edges = include;
83 self
84 }
85
86 pub fn with_max_depth(mut self, depth: usize) -> Self {
88 self.max_depth = Some(depth);
89 self
90 }
91
92 pub fn matches_node(&self, node: &StateNode) -> bool {
94 if let Some(ref types) = self.node_types {
96 if !types.contains(&node.node_type) {
97 return false;
98 }
99 }
100
101 if let Some(ref layers) = self.layers {
103 if !layers.contains(&node.layer) {
104 return false;
105 }
106 }
107
108 if let Some(ref ids) = self.node_ids {
110 if !ids.contains(&node.id) {
111 return false;
112 }
113 }
114
115 true
116 }
117
118 pub fn matches_edge(&self, edge: &StateEdge) -> bool {
120 if let Some(ref types) = self.relationship_types {
122 if !types.contains(&edge.relationship_type) {
123 return false;
124 }
125 }
126
127 true
128 }
129}