kanban-domain 0.3.5

Domain models and business logic for the kanban project management tool
Documentation
use serde::{Deserialize, Serialize};

/// Types of relationships between cards
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CardEdgeType {
    /// This card blocks the target (must complete before target can start)
    /// Enforces DAG - no cycles allowed
    Blocks,

    /// General relationship (informational, allows cycles)
    RelatesTo,

    /// Organizational grouping - parent contains child (source is parent, target is child)
    /// Enforces DAG - no cycles allowed (can't be own ancestor)
    ParentOf,
    // Future edge types can be added here:
    // Duplicates,
}

impl CardEdgeType {
    /// Whether this edge type enforces DAG (no cycles)
    pub fn requires_dag(&self) -> bool {
        matches!(self, CardEdgeType::Blocks | CardEdgeType::ParentOf)
    }

    /// Whether this edge type allows cycles
    pub fn allows_cycles(&self) -> bool {
        !self.requires_dag()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_blocks_requires_dag() {
        assert!(CardEdgeType::Blocks.requires_dag());
        assert!(!CardEdgeType::Blocks.allows_cycles());
    }

    #[test]
    fn test_relates_to_allows_cycles() {
        assert!(!CardEdgeType::RelatesTo.requires_dag());
        assert!(CardEdgeType::RelatesTo.allows_cycles());
    }

    #[test]
    fn test_parent_of_requires_dag() {
        assert!(CardEdgeType::ParentOf.requires_dag());
        assert!(!CardEdgeType::ParentOf.allows_cycles());
    }
}