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

static META: NodeMetadata = NodeMetadata {
    name: "microsoftsharepoint",
    display_name: "Microsoft SharePoint",
    version: &[1],
    group: &["transform"],
    description: "Interact with Microsoft SharePoint API",
    inputs: 1,
    outputs: 1,
    properties: &[
    PropertyDef { name: "resource", display_name: "Resource", kind: PropertyKind::Options, required: false, default: Some("file") }
],
    credentials: &[
    CredentialRef { name: "microsoftSharePointOAuth2Api", required: true }
],
};

#[async_trait]
impl Node for MicrosoftsharepointNode {
    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://{{ $credentials.subdomain }}.sharepoint.com/_api/v2.0/",
            credential: Some("microsoftSharePointOAuth2Api"),
            auth_headers: &[],
            auth_query: &[],
            dispatch_param: "operation",
            operations: &[
                crate::engine::routing::OperationDescriptor {
                    value: "download", method: "GET", url_template: "/sites/{{ $parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "update", method: "PATCH", url_template: "/sites/{{ $parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "upload", method: "PUT", url_template: "/sites/{{ $parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "get", method: "GET", url_template: "/sites/{{ $parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "getAll", method: "GET", url_template: "/sites/{{ $parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "create", method: "POST", url_template: "/sites/{{ $parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "upsert", method: "POST", url_template: "/sites/{{ $parameter[",
                    body_template: "", query: &[],
                },
                crate::engine::routing::OperationDescriptor {
                    value: "delete", method: "DELETE", url_template: "/sites/{{ $parameter[",
                    body_template: "", query: &[],
                }
            ],
            sends: &[
                crate::engine::routing::SendDescriptor {
                    param_name: "fileName", send_type: "body", dest_key: "name",
                    operations: &[], resources: &[],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "simplify", send_type: "query", dest_key: "$select",
                    operations: &[], resources: &[],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "limit", send_type: "query", dest_key: "$top",
                    operations: &[], resources: &[],
                },
                crate::engine::routing::SendDescriptor {
                    param_name: "filter", send_type: "query", dest_key: "$filter",
                    operations: &[], resources: &[],
                }
            ],
        };
    crate::engine::routing::execute_routing(&ROUTING, _ctx).await
    }
}

inventory::submit! { NodeFactory::new("microsoftsharepoint", || Arc::new(MicrosoftsharepointNode)) }
