// AUTO-GENERATED — do not edit by hand
// Upstream: https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/Metabase/Metabase.node.ts
// To implement: copy to ../impl/metabase.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 MetabaseNode;

static META: NodeMetadata = NodeMetadata {
    name: "metabase",
    display_name: "Metabase",
    version: &[1],
    group: &["transform"],
    description: "Use the Metabase API",
    inputs: 1,
    outputs: 1,
    properties: &[
    PropertyDef { name: "resource", display_name: "Resource", kind: PropertyKind::Options, required: false, default: Some("questions") }
],
    credentials: &[
    CredentialRef { name: "metabaseApi", required: true }
],
};

#[async_trait]
impl Node for MetabaseNode {
    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.url.replace(new RegExp(",
            credential: Some("metabaseApi"),
            auth_headers: &[("X-Metabase-Session", "{{sessionToken}}")],
            auth_query: &[],
            dispatch_param: "operation",
            operations: &[
                crate::engine::routing::OperationDescriptor {
                    value: "get", method: "GET", url_template: "{{",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "getAll", method: "GET", url_template: "/api/card/",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "resultData", method: "POST", url_template: "{{",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "addNewDatasource", method: "POST", url_template: "/api/database",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "getFields", method: "GET", url_template: "{{",
                    body_template: "", query: &[],
                }
            ],
            sends: &[
                crate::engine::routing::SendDescriptor {
                    param_name: "Sqlite", send_type: "body", dest_key: "engine",
                    operations: &["addNewDatasource"], resources: &["databases"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "host", send_type: "body", dest_key: "details.host",
                    operations: &["addNewDatasource"], resources: &["databases"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "name", send_type: "body", dest_key: "name",
                    operations: &["addNewDatasource"], resources: &["databases"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "port", send_type: "body", dest_key: "details.port",
                    operations: &["addNewDatasource"], resources: &["databases"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "user", send_type: "body", dest_key: "details.user",
                    operations: &["addNewDatasource"], resources: &["databases"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "password", send_type: "body", dest_key: "details.password",
                    operations: &["addNewDatasource"], resources: &["databases"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "dbName", send_type: "body", dest_key: "details.db",
                    operations: &["addNewDatasource"], resources: &["databases"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "filePath", send_type: "body", dest_key: "details.db",
                    operations: &["addNewDatasource"], resources: &["databases"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "fullSync", send_type: "body", dest_key: "is_full_sync",
                    operations: &["addNewDatasource"], resources: &["databases"],
                }
            ],
        };
    crate::engine::routing::execute_routing(&ROUTING, _ctx).await
    }
}

inventory::submit! { NodeFactory::new("metabase", || Arc::new(MetabaseNode)) }
