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

static META: NodeMetadata = NodeMetadata {
    name: "gong",
    display_name: "Gong",
    version: &[1],
    group: &["transform"],
    description: "Interact with Gong API",
    inputs: 1,
    outputs: 1,
    properties: &[
    PropertyDef { name: "authentication", display_name: "Authentication", kind: PropertyKind::Options, required: false, default: Some("accessToken") },
    PropertyDef { name: "resource", display_name: "Resource", kind: PropertyKind::Options, required: false, default: Some("call") }
],
    credentials: &[
    CredentialRef { name: "gongApi", required: true },
    CredentialRef { name: "gongOAuth2Api", required: true }
],
};

#[async_trait]
impl Node for GongNode {
    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("gongApi"),
            auth_headers: &[],
            auth_query: &[],
            dispatch_param: "operation",
            operations: &[
                crate::engine::routing::OperationDescriptor {
                    value: "get", method: "POST", url_template: "/v2/calls/extensive",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "getAll", method: "POST", url_template: "/v2/calls/extensive",
                    body_template: "filter: {},", query: &[],
                }
            ],
            sends: &[
                crate::engine::routing::SendDescriptor {
                    param_name: "url", send_type: "body", dest_key: "filter.callIds",
                    operations: &["get"], resources: &["call"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "Brief", send_type: "body", dest_key: "contentSelector.exposedFields.content.brief",
                    operations: &["get"], resources: &["call"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "fromDateTime", send_type: "body", dest_key: "filter.fromDateTime",
                    operations: &["getAll"], resources: &["call"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "toDateTime", send_type: "body", dest_key: "filter.toDateTime",
                    operations: &["getAll"], resources: &["call"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "workspaceId", send_type: "body", dest_key: "filter.workspaceId",
                    operations: &["getAll"], resources: &["call"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "id", send_type: "body", dest_key: "filter.primaryUserIds",
                    operations: &[], resources: &[],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "createdFromDateTime", send_type: "body", dest_key: "filter.createdFromDateTime",
                    operations: &["getAll"], resources: &["user"],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "createdToDateTime", send_type: "body", dest_key: "filter.createdToDateTime",
                    operations: &["getAll"], resources: &["user"],
                }
            ],
        };
    crate::engine::routing::execute_routing(&ROUTING, _ctx).await
    }
}

inventory::submit! { NodeFactory::new("gong", || Arc::new(GongNode)) }
