use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VariableScope {
pub scope_id: String,
pub scope_type: ScopeType,
pub parent_scope_id: Option<String>,
pub variables: HashMap<String, ScopedVariable>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ScopeType {
Workflow,
Branch,
Step,
Iteration,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScopedVariable {
pub name: String,
pub value: serde_json::Value,
pub var_type: VariableType,
pub immutable: bool,
pub set_at: DateTime<Utc>,
pub set_by: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum VariableType {
String,
Integer,
Float,
Boolean,
Array,
Object,
Null,
Any,
}
impl VariableType {
pub fn matches(&self, value: &serde_json::Value) -> bool {
match self {
Self::String => value.is_string(),
Self::Integer => value.is_i64() || value.is_u64(),
Self::Float => value.is_f64(),
Self::Boolean => value.is_boolean(),
Self::Array => value.is_array(),
Self::Object => value.is_object(),
Self::Null => value.is_null(),
Self::Any => true,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeCheckResult {
pub valid: bool,
pub errors: Vec<TypeCheckError>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TypeCheckError {
pub variable_name: String,
pub scope_id: String,
pub expected: VariableType,
pub actual: String,
pub message: String,
}