use panproto_gat::CompositionSpec;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct EdgeRule {
pub edge_kind: String,
pub src_kinds: Vec<String>,
pub tgt_kinds: Vec<String>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[allow(clippy::struct_excessive_bools)]
pub struct Protocol {
pub name: String,
pub schema_theory: String,
pub instance_theory: String,
pub schema_composition: Option<CompositionSpec>,
pub instance_composition: Option<CompositionSpec>,
pub edge_rules: Vec<EdgeRule>,
pub obj_kinds: Vec<String>,
pub constraint_sorts: Vec<String>,
#[serde(default)]
pub has_order: bool,
#[serde(default)]
pub has_coproducts: bool,
#[serde(default)]
pub has_recursion: bool,
#[serde(default)]
pub has_causal: bool,
#[serde(default)]
pub nominal_identity: bool,
#[serde(default)]
pub has_defaults: bool,
#[serde(default)]
pub has_coercions: bool,
#[serde(default)]
pub has_mergers: bool,
#[serde(default)]
pub has_policies: bool,
}
impl Protocol {
#[must_use]
pub fn find_edge_rule(&self, edge_kind: &str) -> Option<&EdgeRule> {
self.edge_rules.iter().find(|r| r.edge_kind == edge_kind)
}
#[must_use]
pub fn is_known_vertex_kind(&self, kind: &str) -> bool {
if self.obj_kinds.iter().any(|k| k == kind) {
return true;
}
for rule in &self.edge_rules {
if rule.src_kinds.iter().any(|k| k == kind) {
return true;
}
if rule.tgt_kinds.iter().any(|k| k == kind) {
return true;
}
}
false
}
}