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

static META: NodeMetadata = NodeMetadata {
    name: "adalo",
    display_name: "Adalo",
    version: &[1],
    group: &["transform"],
    description: "Consume Adalo API",
    inputs: 1,
    outputs: 1,
    properties: &[
    PropertyDef { name: "resource", display_name: "Resource", kind: PropertyKind::Options, required: false, default: Some("collection") },
    PropertyDef { name: "operation", display_name: "Operation", kind: PropertyKind::Options, required: false, default: Some("getAll") },
    PropertyDef { name: "collectionId", display_name: "Collection ID", kind: PropertyKind::String, required: true, default: Some("") }
],
    credentials: &[
    CredentialRef { name: "adaloApi", required: true }
],
};

#[async_trait]
impl Node for AdaloNode {
    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: "=https://api.adalo.com/v0/apps/{{$credentials.appId}}",
            credential: Some("adaloApi"),
            auth_headers: &[("Authorization", "Bearer {{apiKey}}")],
            auth_query: &[],
            dispatch_param: "operation",
            operations: &[
                crate::engine::routing::OperationDescriptor {
                    value: "create", method: "POST", url_template: "/collections/{{$parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "delete", method: "DELETE", url_template: "/collections/{{$parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "get", method: "GET", url_template: "/collections/{{$parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "getAll", method: "GET", url_template: "/collections/{{$parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "update", method: "PUT", url_template: "/collections/{{$parameter[",
                    body_template: "", query: &[],
                }
            ],
            sends: &[],
        };
    crate::engine::routing::execute_routing(&ROUTING, _ctx).await
    }
}

inventory::submit! { NodeFactory::new("adalo", || Arc::new(AdaloNode)) }
