# Copyright (c) 2025 Patrick Motsch
# SharePoint node definitions - map to methodSharepoint actions.

from modules.shared.i18nRegistry import t

SHAREPOINT_NODES = [
    {
        "id": "sharepoint.findFile",
        "category": "sharepoint",
        "label": t("Datei finden"),
        "description": t("Datei nach Pfad oder Suche finden"),
        "parameters": [
            {"name": "connectionReference", "type": "string", "required": True, "frontendType": "userConnection",
             "description": t("SharePoint-Verbindung")},
            {"name": "searchQuery", "type": "string", "required": True, "frontendType": "text",
             "description": t("Suchanfrage oder Pfad")},
            {"name": "site", "type": "string", "required": False, "frontendType": "text",
             "description": t("Optionaler Site-Hinweis"), "default": ""},
            {"name": "maxResults", "type": "number", "required": False, "frontendType": "number",
             "description": t("Max Ergebnisse"), "default": 1000},
        ],
        "inputs": 1,
        "outputs": 1,
        "inputPorts": {0: {"accepts": ["Transit"]}},
        "outputPorts": {0: {"schema": "FileList"}},
        "meta": {"icon": "mdi-file-search", "color": "#0078D4"},
        "_method": "sharepoint",
        "_action": "findDocumentPath",
    },
    {
        "id": "sharepoint.readFile",
        "category": "sharepoint",
        "label": t("Datei lesen"),
        "description": t("Inhalt aus Datei extrahieren"),
        "parameters": [
            {"name": "connectionReference", "type": "string", "required": True, "frontendType": "userConnection",
             "description": t("SharePoint-Verbindung")},
            {"name": "pathQuery", "type": "string", "required": True, "frontendType": "sharepointFile",
             "frontendOptions": {"dependsOn": "connectionReference"},
             "description": t("Dateipfad")},
        ],
        "inputs": 1,
        "outputs": 1,
        "inputPorts": {0: {"accepts": ["FileList", "Transit"]}},
        "outputPorts": {0: {"schema": "DocumentList"}},
        "meta": {"icon": "mdi-file-document", "color": "#0078D4"},
        "_method": "sharepoint",
        "_action": "readDocuments",
    },
    {
        "id": "sharepoint.uploadFile",
        "category": "sharepoint",
        "label": t("Datei hochladen"),
        "description": t("Datei zu SharePoint hochladen"),
        "parameters": [
            {"name": "connectionReference", "type": "string", "required": True, "frontendType": "userConnection",
             "description": t("SharePoint-Verbindung")},
            {"name": "pathQuery", "type": "string", "required": True, "frontendType": "sharepointFolder",
             "frontendOptions": {"dependsOn": "connectionReference"},
             "description": t("Zielordner-Pfad")},
        ],
        "inputs": 1,
        "outputs": 1,
        "inputPorts": {0: {"accepts": ["DocumentList", "Transit"]}},
        "outputPorts": {0: {"schema": "ActionResult"}},
        "meta": {"icon": "mdi-upload", "color": "#0078D4"},
        "_method": "sharepoint",
        "_action": "uploadFile",
    },
    {
        "id": "sharepoint.listFiles",
        "category": "sharepoint",
        "label": t("Dateien auflisten"),
        "description": t("Dateien in Ordner auflisten"),
        "parameters": [
            {"name": "connectionReference", "type": "string", "required": True, "frontendType": "userConnection",
             "description": t("SharePoint-Verbindung")},
            {"name": "pathQuery", "type": "string", "required": False, "frontendType": "sharepointFolder",
             "frontendOptions": {"dependsOn": "connectionReference"},
             "description": t("Ordnerpfad"), "default": "/"},
        ],
        "inputs": 1,
        "outputs": 1,
        "inputPorts": {0: {"accepts": ["Transit"]}},
        "outputPorts": {0: {"schema": "FileList"}},
        "meta": {"icon": "mdi-folder-open", "color": "#0078D4"},
        "_method": "sharepoint",
        "_action": "listDocuments",
    },
    {
        "id": "sharepoint.downloadFile",
        "category": "sharepoint",
        "label": t("Datei herunterladen"),
        "description": t("Datei vom Pfad herunterladen"),
        "parameters": [
            {"name": "connectionReference", "type": "string", "required": True, "frontendType": "userConnection",
             "description": t("SharePoint-Verbindung")},
            {"name": "pathQuery", "type": "string", "required": True, "frontendType": "sharepointFile",
             "frontendOptions": {"dependsOn": "connectionReference"},
             "description": t("Vollständiger Dateipfad")},
        ],
        "inputs": 1,
        "outputs": 1,
        "inputPorts": {0: {"accepts": ["FileList", "Transit"]}},
        "outputPorts": {0: {"schema": "DocumentList"}},
        "meta": {"icon": "mdi-download", "color": "#0078D4"},
        "_method": "sharepoint",
        "_action": "downloadFileByPath",
    },
    {
        "id": "sharepoint.copyFile",
        "category": "sharepoint",
        "label": t("Datei kopieren"),
        "description": t("Datei an Ziel kopieren"),
        "parameters": [
            {"name": "connectionReference", "type": "string", "required": True, "frontendType": "userConnection",
             "description": t("SharePoint-Verbindung")},
            {"name": "sourcePath", "type": "string", "required": True, "frontendType": "sharepointFile",
             "frontendOptions": {"dependsOn": "connectionReference"},
             "description": t("Quelldatei-Pfad")},
            {"name": "destPath", "type": "string", "required": True, "frontendType": "sharepointFolder",
             "frontendOptions": {"dependsOn": "connectionReference"},
             "description": t("Zielordner")},
        ],
        "inputs": 1,
        "outputs": 1,
        "inputPorts": {0: {"accepts": ["Transit"]}},
        "outputPorts": {0: {"schema": "ActionResult"}},
        "meta": {"icon": "mdi-content-copy", "color": "#0078D4"},
        "_method": "sharepoint",
        "_action": "copyFile",
    },
]
