# Copyright (c) 2025 Patrick Motsch
# Email node definitions - map to methodOutlook actions.

from modules.shared.i18nRegistry import t

EMAIL_NODES = [
    {
        "id": "email.checkEmail",
        "category": "email",
        "label": t("E-Mail prüfen"),
        "description": t("Neue E-Mails prüfen"),
        "parameters": [
            {"name": "connectionReference", "type": "string", "required": True, "frontendType": "userConnection",
             "description": t("E-Mail-Konto Verbindung")},
            {"name": "folder", "type": "string", "required": False, "frontendType": "text",
             "description": t("Ordner"), "default": "Inbox"},
            {"name": "limit", "type": "number", "required": False, "frontendType": "number",
             "description": t("Max E-Mails"), "default": 100},
            {"name": "fromAddress", "type": "string", "required": False, "frontendType": "text",
             "description": t("Nur von dieser Adresse"), "default": ""},
            {"name": "subjectContains", "type": "string", "required": False, "frontendType": "text",
             "description": t("Betreff muss enthalten"), "default": ""},
            {"name": "hasAttachment", "type": "boolean", "required": False, "frontendType": "checkbox",
             "description": t("Nur mit Anhängen"), "default": False},
            {"name": "filter", "type": "string", "required": False, "frontendType": "text",
             "description": t("Erweitert: Filter-Text"), "default": ""},
        ],
        "inputs": 1,
        "outputs": 1,
        "inputPorts": {0: {"accepts": ["Transit"]}},
        "outputPorts": {0: {"schema": "EmailList"}},
        "meta": {"icon": "mdi-email-check", "color": "#1976D2"},
        "_method": "outlook",
        "_action": "readEmails",
    },
    {
        "id": "email.searchEmail",
        "category": "email",
        "label": t("E-Mail suchen"),
        "description": t("E-Mails suchen"),
        "parameters": [
            {"name": "connectionReference", "type": "string", "required": True, "frontendType": "userConnection",
             "description": t("E-Mail-Konto Verbindung")},
            {"name": "query", "type": "string", "required": False, "frontendType": "text",
             "description": t("Suchbegriff"), "default": ""},
            {"name": "folder", "type": "string", "required": False, "frontendType": "text",
             "description": t("Ordner"), "default": "Inbox"},
            {"name": "limit", "type": "number", "required": False, "frontendType": "number",
             "description": t("Max E-Mails"), "default": 100},
            {"name": "fromAddress", "type": "string", "required": False, "frontendType": "text",
             "description": t("Von Adresse"), "default": ""},
            {"name": "toAddress", "type": "string", "required": False, "frontendType": "text",
             "description": t("An Adresse"), "default": ""},
            {"name": "subjectContains", "type": "string", "required": False, "frontendType": "text",
             "description": t("Betreff enthält"), "default": ""},
            {"name": "bodyContains", "type": "string", "required": False, "frontendType": "text",
             "description": t("Inhalt enthält"), "default": ""},
            {"name": "hasAttachment", "type": "boolean", "required": False, "frontendType": "checkbox",
             "description": t("Mit Anhängen"), "default": False},
            {"name": "filter", "type": "string", "required": False, "frontendType": "text",
             "description": t("Erweitert: KQL-Filter"), "default": ""},
        ],
        "inputs": 1,
        "outputs": 1,
        "inputPorts": {0: {"accepts": ["Transit"]}},
        "outputPorts": {0: {"schema": "EmailList"}},
        "meta": {"icon": "mdi-email-search", "color": "#1976D2"},
        "_method": "outlook",
        "_action": "searchEmails",
    },
    {
        "id": "email.draftEmail",
        "category": "email",
        "label": t("E-Mail entwerfen"),
        "description": t("E-Mail-Entwurf erstellen"),
        "parameters": [
            {"name": "connectionReference", "type": "string", "required": True, "frontendType": "userConnection",
             "description": t("E-Mail-Konto")},
            {"name": "subject", "type": "string", "required": True, "frontendType": "text",
             "description": t("Betreff")},
            {"name": "body", "type": "string", "required": True, "frontendType": "textarea",
             "description": t("Inhalt")},
            {"name": "to", "type": "string", "required": False, "frontendType": "text",
             "description": t("Empfänger"), "default": ""},
        ],
        "inputs": 1,
        "outputs": 1,
        "inputPorts": {0: {"accepts": ["EmailDraft", "AiResult", "Transit"]}},
        "outputPorts": {0: {"schema": "ActionResult"}},
        "meta": {"icon": "mdi-email-edit", "color": "#1976D2"},
        "_method": "outlook",
        "_action": "composeAndDraftEmailWithContext",
    },
]
