/*
 * Orvanta API
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 1.2.0
 * Contact: contact@orvanta.cloud
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// FlowValue : The flow structure containing modules and optional preprocessor/failure handlers
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct FlowValue {
    /// Array of steps that execute in sequence. Each step can be a script, subflow, loop, or branch
    #[serde(rename = "modules")]
    pub modules: Vec<models::FlowModule>,
    #[serde(rename = "failure_module", skip_serializing_if = "Option::is_none")]
    pub failure_module: Option<Box<models::FlowModule>>,
    #[serde(rename = "preprocessor_module", skip_serializing_if = "Option::is_none")]
    pub preprocessor_module: Option<Box<models::FlowModule>>,
    /// If true, all steps run on the same worker for better performance
    #[serde(rename = "same_worker", skip_serializing_if = "Option::is_none")]
    pub same_worker: Option<bool>,
    /// Maximum number of concurrent executions of this flow
    #[serde(rename = "concurrent_limit", skip_serializing_if = "Option::is_none")]
    pub concurrent_limit: Option<f64>,
    /// Expression to group concurrent executions (e.g., by user ID)
    #[serde(rename = "concurrency_key", skip_serializing_if = "Option::is_none")]
    pub concurrency_key: Option<String>,
    /// Time window in seconds for concurrent_limit
    #[serde(rename = "concurrency_time_window_s", skip_serializing_if = "Option::is_none")]
    pub concurrency_time_window_s: Option<f64>,
    /// Delay in seconds to debounce flow executions
    #[serde(rename = "debounce_delay_s", skip_serializing_if = "Option::is_none")]
    pub debounce_delay_s: Option<i32>,
    /// Expression to group debounced executions
    #[serde(rename = "debounce_key", skip_serializing_if = "Option::is_none")]
    pub debounce_key: Option<String>,
    /// Arguments to accumulate across debounced executions
    #[serde(rename = "debounce_args_to_accumulate", skip_serializing_if = "Option::is_none")]
    pub debounce_args_to_accumulate: Option<Vec<String>>,
    /// Maximum total time in seconds that a job can be debounced
    #[serde(rename = "max_total_debouncing_time", skip_serializing_if = "Option::is_none")]
    pub max_total_debouncing_time: Option<i32>,
    /// Maximum number of times a job can be debounced
    #[serde(rename = "max_total_debounces_amount", skip_serializing_if = "Option::is_none")]
    pub max_total_debounces_amount: Option<i32>,
    /// JavaScript expression to conditionally skip the entire flow
    #[serde(rename = "skip_expr", skip_serializing_if = "Option::is_none")]
    pub skip_expr: Option<String>,
    /// Cache duration in seconds for flow results
    #[serde(rename = "cache_ttl", skip_serializing_if = "Option::is_none")]
    pub cache_ttl: Option<f64>,
    #[serde(rename = "cache_ignore_s3_path", skip_serializing_if = "Option::is_none")]
    pub cache_ignore_s3_path: Option<bool>,
    /// If set, delete the flow job's args, result and logs after this many seconds following job completion
    #[serde(rename = "delete_after_secs", skip_serializing_if = "Option::is_none")]
    pub delete_after_secs: Option<i32>,
    /// Environment variables available to all steps. Values can be strings, JSON values, or special references: '$var:path' (workspace variable) or '$res:path' (resource).
    #[serde(rename = "flow_env", skip_serializing_if = "Option::is_none")]
    pub flow_env: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// Execution priority (higher numbers run first)
    #[serde(rename = "priority", skip_serializing_if = "Option::is_none")]
    pub priority: Option<f64>,
    /// JavaScript expression to return early from the flow
    #[serde(rename = "early_return", skip_serializing_if = "Option::is_none")]
    pub early_return: Option<String>,
    /// Whether this flow accepts chat-style input
    #[serde(rename = "chat_input_enabled", skip_serializing_if = "Option::is_none")]
    pub chat_input_enabled: Option<bool>,
    /// Sticky notes attached to the flow
    #[serde(rename = "notes", skip_serializing_if = "Option::is_none")]
    pub notes: Option<Vec<models::FlowNote>>,
    /// Semantic groups of modules for organizational purposes
    #[serde(rename = "groups", skip_serializing_if = "Option::is_none")]
    pub groups: Option<Vec<models::FlowGroup>>,
}

impl FlowValue {
    /// The flow structure containing modules and optional preprocessor/failure handlers
    pub fn new(modules: Vec<models::FlowModule>) -> FlowValue {
        FlowValue {
            modules,
            failure_module: None,
            preprocessor_module: None,
            same_worker: None,
            concurrent_limit: None,
            concurrency_key: None,
            concurrency_time_window_s: None,
            debounce_delay_s: None,
            debounce_key: None,
            debounce_args_to_accumulate: None,
            max_total_debouncing_time: None,
            max_total_debounces_amount: None,
            skip_expr: None,
            cache_ttl: None,
            cache_ignore_s3_path: None,
            delete_after_secs: None,
            flow_env: None,
            priority: None,
            early_return: None,
            chat_input_enabled: None,
            notes: None,
            groups: None,
        }
    }
}

