"""AI Assistant plugin — multi-provider LLM chat, agents, tools."""

from __future__ import annotations

import logging
from typing import Any

from app.plugins.base import BasePlugin
from app.plugins.manifest import PluginManifest, PluginRouteDef

logger = logging.getLogger(__name__)


class AIAssistantPlugin(BasePlugin):
    """AI Assistant plugin: multi-provider LLM chat with agents and tools."""

    manifest = PluginManifest(
        name="ai_assistant",
        version="1.0.0",
        display_name="KI Assistent",
        description=(
            "AI Assistant with multi-provider LLM support, custom agents, "
            "plugin tools, and streaming chat."
        ),
        dependencies=[],
        routes=[
            PluginRouteDef(
                path="/api/v1/ai",
                module="app.plugins.builtins.ai_assistant.routes",
                router_attr="router",
            ),
        ],
        events=[],
        migrations=["0001_initial.sql", "0002_folders_attachments.sql"],
        permissions=[
            "ai:read",
            "ai:write",
            "ai:config",
            "ai:agents",
            "ai:tools",
        ],
        is_core=True,
    )

    async def on_install(self, db, service_container) -> None:
        """Seed default provider and agent."""
        from app.plugins.builtins.ai_assistant.services import seed_defaults

        await seed_defaults(db)

    def get_notification_types(self) -> list[dict[str, Any]]:
        return [
            {
                "type_key": "ai_response_error",
                "category": "ai",
                "label": "KI Antwort-Fehler",
                "description": "Fehler bei der KI-Antwortgenerierung",
                "is_enabled_by_default": True,
            },
        ]
