use crate::forme::MemberId;
use crate::forme::subgraph::SubgraphId;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(bound = "")]
pub struct MemberEntry<N: MemberId> {
pub lifecycle: Lifecycle,
pub provenance: Provenance<N>,
pub subgraph_membership: Vec<SubgraphId>,
pub layout_override: Option<LayoutOverride>,
}
impl<N: MemberId> MemberEntry<N> {
pub fn new(lifecycle: Lifecycle, provenance: Provenance<N>) -> Self {
Self {
lifecycle,
provenance,
subgraph_membership: Vec::new(),
layout_override: None,
}
}
pub fn with_subgraph(mut self, id: SubgraphId) -> Self {
self.subgraph_membership.push(id);
self
}
pub fn with_layout_override(mut self, lo: LayoutOverride) -> Self {
self.layout_override = Some(lo);
self
}
pub fn is_active(&self) -> bool {
self.lifecycle == Lifecycle::Active
}
pub fn is_warm(&self) -> bool {
self.lifecycle == Lifecycle::Warm
}
pub fn is_cold(&self) -> bool {
self.lifecycle == Lifecycle::Cold
}
pub fn is_visible_in_pane(&self) -> bool {
matches!(self.lifecycle, Lifecycle::Active | Lifecycle::Warm)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Lifecycle {
Active,
Warm,
Cold,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(bound = "")]
pub enum Provenance<N: MemberId> {
Traversal {
source: N,
edge_kind: Option<String>,
},
Manual {
source: Option<N>,
context: Option<String>,
},
Anchor,
Derived {
connection: Option<N>,
derivation: String,
},
AgentDerived {
confidence: f32,
agent: String,
source: Option<N>,
},
Restored,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct LayoutOverride {
pub min_width: Option<f32>,
pub min_height: Option<f32>,
pub flex_grow: Option<f32>,
pub flex_shrink: Option<f32>,
pub preferred_split: Option<SplitDirection>,
pub split_ratio: Option<f32>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum SplitDirection {
Horizontal,
Vertical,
}