db/heromodels/src/models/flow/signature_requirement.rs
2025-06-25 03:27:22 +02:00

71 lines
2.0 KiB
Rust

use heromodels_core::BaseModelData;
use heromodels_derive::model;
use rhai::{CustomType, TypeBuilder};
use serde::{Deserialize, Serialize};
use std::default::Default;
/// Represents a signature requirement for a flow step.
#[derive(Debug, Clone, Serialize, Deserialize, Default, CustomType)]
#[model]
pub struct SignatureRequirement {
/// Base model data.
#[rhai_type(skip)]
pub base_data: BaseModelData,
/// Foreign key to the FlowStep this requirement belongs to.
#[index]
pub flow_step_id: u32,
/// The public key required to sign the message.
pub public_key: String,
/// The plaintext message to be signed.
pub message: String,
/// The public key of the entity that signed the message, if signed.
pub signed_by: Option<String>,
/// The signature, if signed.
pub signature: Option<String>,
/// Current status of the signature requirement (e.g., "Pending", "SentToClient", "Signed", "Failed", "Error").
pub status: String,
}
impl SignatureRequirement {
/// Create a new signature requirement.
pub fn new(
_id: u32,
flow_step_id: u32,
public_key: impl ToString,
message: impl ToString,
) -> Self {
Self {
base_data: BaseModelData::new(),
flow_step_id,
public_key: public_key.to_string(),
message: message.to_string(),
signed_by: None,
signature: None,
status: String::from("Pending"), // Default status
}
}
/// Sets the public key of the signer.
pub fn signed_by(mut self, signed_by: impl ToString) -> Self {
self.signed_by = Some(signed_by.to_string());
self
}
/// Sets the signature.
pub fn signature(mut self, signature: impl ToString) -> Self {
self.signature = Some(signature.to_string());
self
}
pub fn status(mut self, status: impl ToString) -> Self {
self.status = status.to_string();
self
}
}