/*
 * Zernio API
 *
 * API reference for Zernio. Authenticate with a Bearer API key. Base URL: https://zernio.com/api
 *
 * The version of the OpenAPI document: 1.0.4
 * Contact: support@zernio.com
 * Generated by: https://openapi-generator.tech
 */

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

/// WorkflowExecutionEvent : One entry in a workflow execution's timeline. Emitted by the executor on every node visit and lifecycle transition, surfaced by `GET /v1/workflows/{workflowId}/executions/ {executionId}/events` for run inspection in the Runs UI.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct WorkflowExecutionEvent {
    #[serde(rename = "action", skip_serializing_if = "Option::is_none")]
    pub action: Option<Action>,
    #[serde(
        rename = "status",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub status: Option<Option<Status>>,
    /// Present on `node_*` events
    #[serde(
        rename = "nodeId",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub node_id: Option<Option<String>>,
    /// Present on `node_*` events
    #[serde(
        rename = "nodeType",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub node_type: Option<Option<String>>,
    /// The edge handle the executor followed out of this node (see `WorkflowEdge.sourceHandle`)
    #[serde(
        rename = "sourceHandle",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub source_handle: Option<Option<String>>,
    /// Node run time; present on `node_completed` and `node_failed`
    #[serde(
        rename = "durationMs",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub duration_ms: Option<Option<i32>>,
    /// Failure detail; present on `node_failed` and `execution_exited`
    #[serde(
        rename = "errorMessage",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub error_message: Option<Option<String>>,
    /// Per-node-type payload. Shape varies — see WorkflowNode `type`. Examples:   `send_message` → `{ messageType, text, recipient }`,   `webhook` → `{ url, method, statusCode, responseTimeMs, responsePreview }`,   `ai` → `{ model, provider, inputTokens, outputTokens, responsePreview }`,   `condition` → `{ matchedHandle, rulesEvaluated }`,   `a_b_split` → `{ percentage, chosen }`.
    #[serde(
        rename = "meta",
        default,
        with = "::serde_with::rust::double_option",
        skip_serializing_if = "Option::is_none"
    )]
    pub meta: Option<Option<std::collections::HashMap<String, serde_json::Value>>>,
    /// Event timestamp (UTC)
    #[serde(rename = "at", skip_serializing_if = "Option::is_none")]
    pub at: Option<String>,
}

impl WorkflowExecutionEvent {
    /// One entry in a workflow execution's timeline. Emitted by the executor on every node visit and lifecycle transition, surfaced by `GET /v1/workflows/{workflowId}/executions/ {executionId}/events` for run inspection in the Runs UI.
    pub fn new() -> WorkflowExecutionEvent {
        WorkflowExecutionEvent {
            action: None,
            status: None,
            node_id: None,
            node_type: None,
            source_handle: None,
            duration_ms: None,
            error_message: None,
            meta: None,
            at: None,
        }
    }
}
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Action {
    #[serde(rename = "execution_started")]
    ExecutionStarted,
    #[serde(rename = "execution_completed")]
    ExecutionCompleted,
    #[serde(rename = "execution_exited")]
    ExecutionExited,
    #[serde(rename = "execution_paused")]
    ExecutionPaused,
    #[serde(rename = "execution_resumed")]
    ExecutionResumed,
    #[serde(rename = "node_started")]
    NodeStarted,
    #[serde(rename = "node_completed")]
    NodeCompleted,
    #[serde(rename = "node_failed")]
    NodeFailed,
    #[serde(rename = "node_skipped")]
    NodeSkipped,
}

impl Default for Action {
    fn default() -> Action {
        Self::ExecutionStarted
    }
}
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Status {
    #[serde(rename = "success")]
    Success,
    #[serde(rename = "failed")]
    Failed,
    #[serde(rename = "pending")]
    Pending,
}

impl Default for Status {
    fn default() -> Status {
        Self::Success
    }
}
