// AUTO-GENERATED — do not edit by hand
// Upstream: https://github.com/n8n-io/n8n/blob/master/packages/@n8n/nodes-langchain/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.ts
// To implement: copy to ../impl/openaiassistant.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 OpenaiassistantNode;

static META: NodeMetadata = NodeMetadata {
    name: "openaiassistant",
    display_name: "OpenAI Assistant",
    version: &[1],
    group: &["transform"],
    description: "Utilizes Assistant API from Open AI.",
    inputs: 1,
    outputs: 1,
    properties: &[
    PropertyDef { name: "mode", display_name: "Operation", kind: PropertyKind::Options, required: false, default: Some("existing") },
    PropertyDef { name: "name", display_name: "Name", kind: PropertyKind::String, required: true, default: Some("") },
    PropertyDef { name: "instructions", display_name: "Instructions", kind: PropertyKind::String, required: false, default: Some("") },
    PropertyDef { name: "model", display_name: "Model", kind: PropertyKind::Options, required: true, default: Some("gpt-3.5-turbo-1106") },
    PropertyDef { name: "assistantId", display_name: "Assistant", kind: PropertyKind::Options, required: true, default: Some("") },
    PropertyDef { name: "text", display_name: "Text", kind: PropertyKind::String, required: true, default: Some("={{ $json.chat_input }}") },
    PropertyDef { name: "text", display_name: "Text", kind: PropertyKind::String, required: true, default: Some("={{ $json.chatInput }}") },
    PropertyDef { name: "nativeTools", display_name: "OpenAI Tools", kind: PropertyKind::MultiOptions, required: false, default: None },
    PropertyDef { name: "noticeTools", display_name: "Connect your own custom tools to this node on the canvas", kind: PropertyKind::Notice, required: false, default: Some("") },
    PropertyDef { name: "noticeTools", display_name: "Upload files for retrieval using the <a href=", kind: PropertyKind::Notice, required: false, default: Some("") },
    PropertyDef { name: "options", display_name: "Options", kind: PropertyKind::Collection, required: false, default: Some("https://api.openai.com/v1") }
],
    credentials: &[
    CredentialRef { name: "openAiApi", required: true }
],
};

#[async_trait]
impl Node for OpenaiassistantNode {
    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: "={{ $parameter.options?.baseURL?.split(",
            credential: Some("openAiApi"),
            auth_headers: &[],
            auth_query: &[],
            dispatch_param: "operation",
            operations: &[],
            sends: &[
                crate::engine::routing::SendDescriptor {
                    param_name: "model", send_type: "body", dest_key: "model",
                    operations: &[], resources: &[],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "assistantId", send_type: "body", dest_key: "assistant",
                    operations: &[], resources: &[],
                }
            ],
        };
    crate::engine::routing::execute_routing(&ROUTING, _ctx).await
    }
}

inventory::submit! { NodeFactory::new("openaiassistant", || Arc::new(OpenaiassistantNode)) }
