db/heromodels/src/models/flow/flow.rs
2025-06-03 21:50:08 +03:00

57 lines
1.5 KiB
Rust

use heromodels_core::BaseModelData;
use heromodels_derive::model;
use serde::{Deserialize, Serialize};
use super::flow_step::FlowStep;
/// Represents a signing flow.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Default)]
#[model]
pub struct Flow {
/// Base model data (id, created_at, updated_at).
pub base_data: BaseModelData,
/// A unique UUID for the flow, for external reference.
#[index]
pub flow_uuid: String,
/// Name of the flow.
#[index]
pub name: String,
/// Current status of the flow (e.g., "Pending", "InProgress", "Completed", "Failed").
pub status: String,
/// Steps involved in this flow.
pub steps: Vec<FlowStep>,
}
impl Flow {
/// Create a new flow.
/// The `flow_uuid` should be a Uuid::new_v4().to_string().
/// The ID is managed by `BaseModelData::new()` and the database.
pub fn new(flow_uuid: impl ToString) -> Self {
Self {
base_data: BaseModelData::new(),
flow_uuid: flow_uuid.to_string(),
name: String::new(), // Default name, to be set by builder
status: String::from("Pending"), // Default status, to be set by builder
steps: Vec::new(),
}
}
pub fn name(mut self, name: impl ToString) -> Self {
self.name = name.to_string();
self
}
pub fn status(mut self, status: impl ToString) -> Self {
self.status = status.to_string();
self
}
pub fn add_step(mut self, step: FlowStep) -> Self {
self.steps.push(step);
self
}
}