// AUTO-GENERATED — do not edit by hand
// Upstream: https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/N8n/N8n.node.ts
// To implement: copy to ../impl/n8n.rs, fill in execute(), add to ../impl/mod.rs
// r8r: rust port of n8n.io
// License: Unlicense

use async_trait::async_trait;
use crate::core::error::NodeError;
use crate::core::types::*;
use crate::engine::{ExecuteCtx, Node, NodeFactory};
use std::sync::Arc;

pub struct N8nNode;

static META: NodeMetadata = NodeMetadata {
    name: "n8n",
    display_name: "n8n",
    version: &[1],
    group: &["transform"],
    description: "Handle events and perform actions on your n8n instance",
    inputs: 1,
    outputs: 1,
    properties: &[
    PropertyDef { name: "resource", display_name: "Resource", kind: PropertyKind::Options, required: false, default: Some("workflow") }
],
    credentials: &[
    CredentialRef { name: "n8nApi", required: true }
],
};

#[async_trait]
impl Node for N8nNode {
    fn metadata(&self) -> &'static NodeMetadata { &META }

    async fn execute(&self, _ctx: &mut ExecuteCtx<'_>) -> Result<NodeOutput, NodeError> {
    static ROUTING: crate::engine::routing::RoutingDescriptor =
        crate::engine::routing::RoutingDescriptor {
            base_url: "={{ $credentials.baseUrl.replace(new RegExp(",
            credential: Some("n8nApi"),
            auth_headers: &[("X-N8N-API-KEY", "{{apiKey}}")],
            auth_query: &[],
            dispatch_param: "operation",
            operations: &[
                crate::engine::routing::OperationDescriptor {
                    value: "get", method: "GET", url_template: "/executions/{{ $parameter.executionId }}",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "getAll", method: "GET", url_template: "/executions",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "delete", method: "DELETE", url_template: "/executions/{{ $parameter.executionId }}",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "create", method: "POST", url_template: "/workflows",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "update", method: "POST", url_template: "/workflows/{{ $value }}/activate",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "getSchema", method: "GET", url_template: "/credentials/schema/{{ $parameter.credentialTypeName }}",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "generate", method: "POST", url_template: "/audit",
                    body_template: "", query: &[],
                }
            ],
            sends: &[
                crate::engine::routing::SendDescriptor {
                    param_name: "filters", send_type: "query", dest_key: "workflowId",
                    operations: &["getAll"], resources: &["execution"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "Waiting", send_type: "query", dest_key: "status",
                    operations: &["getAll"], resources: &["execution"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "activeWorkflows", send_type: "query", dest_key: "includeData",
                    operations: &["getAll"], resources: &["execution"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "versionId", send_type: "body", dest_key: "versionId",
                    operations: &["activate"], resources: &["workflow"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "name", send_type: "body", dest_key: "name",
                    operations: &["activate"], resources: &["workflow"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "description", send_type: "body", dest_key: "description",
                    operations: &["activate"], resources: &["workflow"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "tags", send_type: "query", dest_key: "tags",
                    operations: &["getAll"], resources: &["workflow"],
                }
            ],
        };
    crate::engine::routing::execute_routing(&ROUTING, _ctx).await
    }
}

inventory::submit! { NodeFactory::new("n8n", || Arc::new(N8nNode)) }
