use crate::forme::MemberId;
use serde::{Deserialize, Serialize};
pub type SubgraphId = u32;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(bound = "")]
pub struct SubgraphRef<N: MemberId> {
pub id: SubgraphId,
pub anchors: Vec<N>,
pub primary_anchor: Option<N>,
pub binding: SubgraphBinding,
pub kind: Option<SubgraphKind>,
}
impl<N: MemberId> SubgraphRef<N> {
pub fn new_session(id: SubgraphId) -> Self {
Self {
id,
anchors: Vec::new(),
primary_anchor: None,
binding: SubgraphBinding::UnlinkedSession,
kind: Some(SubgraphKind::Session),
}
}
pub fn with_anchor(mut self, anchor: N) -> Self {
self.primary_anchor = Some(anchor.clone());
self.anchors.push(anchor);
self
}
pub fn with_kind(mut self, kind: SubgraphKind) -> Self {
self.kind = Some(kind);
self
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum SubgraphBinding {
UnlinkedSession,
Linked { spec: SubgraphSpec },
Branched {
parent_spec: SubgraphSpec,
reason: String,
},
}
pub use crate::curation::{SubgraphKind, SubgraphSpec};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum ProjectionSource {
GraphDefault { graph_id: String },
GraphViewOverride { graph_view_id: String },
SelectionOverride {
graph_view_id: String,
seed_nodes: Vec<String>,
},
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct EdgeProjectionSpec {
pub selectors: Vec<String>,
pub source: ProjectionSource,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SubgraphMemberDelta<N: MemberId> {
pub added: Vec<N>,
pub removed: Vec<N>,
pub rebased_seeds: Vec<N>,
}
impl<N: MemberId> SubgraphMemberDelta<N> {
pub fn empty() -> Self {
Self {
added: Vec::new(),
removed: Vec::new(),
rebased_seeds: Vec::new(),
}
}
pub fn is_empty(&self) -> bool {
self.added.is_empty() && self.removed.is_empty() && self.rebased_seeds.is_empty()
}
}
#[derive(Clone, Debug)]
pub struct ReconciliationProposal<N: MemberId> {
pub subgraph_id: SubgraphId,
pub delta: SubgraphMemberDelta<N>,
pub reason: String,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ReconciliationChoice {
ApplyKeepLinked,
KeepAsUnlinkedSession,
SaveAsNewFork { reason: String },
Cancel,
}