use uuid::Uuid;
use crate::core::{BindingId, EdgeId, GroupId, NodeId, PortId, StickyNoteId, SymbolId};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct IdRemapSeed(pub Uuid);
impl IdRemapSeed {
pub fn new_random() -> Self {
Self(Uuid::new_v4())
}
}
#[derive(Debug, Clone)]
pub struct IdRemapper {
seed: IdRemapSeed,
}
impl IdRemapper {
pub fn new(seed: IdRemapSeed) -> Self {
Self { seed }
}
fn remap_uuid(&self, old: Uuid) -> Uuid {
Uuid::new_v5(&self.seed.0, old.as_bytes())
}
pub fn remap_node(&self, id: NodeId) -> NodeId {
NodeId(self.remap_uuid(id.0))
}
pub fn remap_port(&self, id: PortId) -> PortId {
PortId(self.remap_uuid(id.0))
}
pub fn remap_edge(&self, id: EdgeId) -> EdgeId {
EdgeId(self.remap_uuid(id.0))
}
pub fn remap_group(&self, id: GroupId) -> GroupId {
GroupId(self.remap_uuid(id.0))
}
pub fn remap_note(&self, id: StickyNoteId) -> StickyNoteId {
StickyNoteId(self.remap_uuid(id.0))
}
pub fn remap_symbol(&self, id: SymbolId) -> SymbolId {
SymbolId(self.remap_uuid(id.0))
}
pub fn remap_binding(&self, id: BindingId) -> BindingId {
BindingId(self.remap_uuid(id.0))
}
}