made-core 0.5.0

Domain core of MADE: entities, value objects, events, ports. No IO.
Documentation
use serde::{Deserialize, Serialize};

use super::{
    JoinStepCount, OutputFieldGuardCondition, StepId, StepRepeatExhaustedGuardCondition, StepStatus,
};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum GuardCondition {
    Always,
    AllStepsCompleted,
    AnyStepCompleted,
    StepsCompleted(JoinStepCount),
    StepStatus { step_id: StepId, status: StepStatus },
    OutputField(OutputFieldGuardCondition),
    StepRepeatExhausted(StepRepeatExhaustedGuardCondition),
    HumanApproval,
}

impl GuardCondition {
    #[must_use]
    pub fn referenced_step_id(&self) -> Option<&StepId> {
        match self {
            Self::StepStatus { step_id, .. } => Some(step_id),
            Self::OutputField(condition) => Some(condition.step_id()),
            Self::StepRepeatExhausted(condition) => Some(condition.step_id()),
            Self::Always
            | Self::AllStepsCompleted
            | Self::AnyStepCompleted
            | Self::StepsCompleted(_)
            | Self::HumanApproval => None,
        }
    }
}