// r8r: rust port of n8n.io
// Initial author: Michael Cochran <mcochran@cochranblock.org>
// Built for: Tanner Woodrum, intended cofounder
// License: Unlicense (public domain dedication, see UNLICENSE)

use thiserror::Error;

#[derive(Debug, Error)]
pub enum NodeError {
    #[error("node `{node}` not yet ported (see upstream: {upstream})")]
    NotYetPorted {
        node: &'static str,
        upstream: &'static str,
    },

    #[error("missing required parameter `{0}`")]
    MissingParameter(String),

    #[error("missing required credential `{0}`")]
    MissingCredential(String),

    #[error("expression evaluation failed: {0}")]
    Expression(String),

    #[error("http error: {0}")]
    Http(String),

    #[error("json error: {0}")]
    Json(#[from] serde_json::Error),

    #[error("io error: {0}")]
    Io(#[from] std::io::Error),

    #[error("{0}")]
    Other(String),
}

#[derive(Debug, Error)]
pub enum FlowError {
    #[error("workflow file not found: {0}")]
    WorkflowNotFound(String),

    #[error("invalid workflow toml: {0}")]
    InvalidToml(#[from] toml::de::Error),

    #[error("unknown node type: `{0}` (run `r8r list-nodes` to see registered types)")]
    UnknownNodeType(String),

    #[error("node `{node}` failed: {source}")]
    NodeFailed {
        node: String,
        #[source]
        source: NodeError,
    },

    #[error("workflow validation: {0}")]
    Validation(String),
}
