"""
T-UC3: Knowledge Chatbot.

Verifies that the chatbot feature instance exists in HappyLife AG
and that knowledge-base documents are available for upload.
Note: The actual RAG demo runs via workspace, not the chatbot's own index.
"""

import pytest
from pathlib import Path
from tests.demo.conftest import _getFeatureInstances


class TestChatbotSetup:

    def test_chatbotInstanceHappylife(self, db, mandateHappylife):
        """HappyLife must have a chatbot instance."""
        mid = mandateHappylife.get("id")
        instances = _getFeatureInstances(db, mid, "chatbot")
        assert len(instances) >= 1, "No chatbot instance in HappyLife"

    def test_chatbotNotInAlpina(self, db, mandateAlpina):
        """Alpina should NOT have a chatbot instance."""
        mid = mandateAlpina.get("id")
        instances = _getFeatureInstances(db, mid, "chatbot")
        assert len(instances) == 0, "Alpina should not have chatbot"


class TestKnowledgeBaseFiles:

    def test_knowledgeBaseFilesExist(self):
        """Knowledge-base documents must exist in demoData."""
        kbDir = Path(__file__).resolve().parent.parent.parent / "demoData" / "knowledge-base"
        assert kbDir.exists(), f"knowledge-base dir not found at {kbDir}"
        files = list(kbDir.iterdir())
        docs = [f for f in files if f.suffix in (".md", ".html", ".pdf", ".docx", ".txt")]
        assert len(docs) >= 3, f"Expected at least 3 knowledge-base docs, found {len(docs)}: {[f.name for f in docs]}"
