"""DataAnalystCrew — code-interpreter + visualization pipeline.

Generated by ``cognithor init --template data-analyst``. The analyst agent
has access to the ``python_sandbox`` tool so it can execute pandas /
matplotlib code on the supplied CSV. The visualizer agent turns the
analyst's findings into a markdown report with embedded charts.
"""

from __future__ import annotations

from cognithor.crew import Crew, CrewAgent, CrewProcess, CrewTask
from cognithor.crew.decorators import agent, crew, task


class DataAnalystCrew:
    """Sequential data-analyst pipeline.

    - ``analyst`` loads the CSV at ``{csv_path}`` and computes stats via
      the ``python_sandbox`` tool.
    - ``visualizer`` turns those findings into a human-readable report
      with chart descriptions.
    """

    @agent
    def analyst(self) -> CrewAgent:
        return CrewAgent(
            role="Analyst",
            goal="Analysiere die CSV-Daten und liefere strukturierte Statistiken",
            backstory=(
                "Erfahrener Daten-Analyst mit Python/pandas-Fokus. "
                "Nutzt die python_sandbox fuer reproduzierbare Auswertungen."
            ),
            tools=["python_sandbox"],
            llm="ollama/qwen3:8b",
        )

    @agent
    def visualizer(self) -> CrewAgent:
        return CrewAgent(
            role="Visualizer",
            goal="Erstelle einen gut lesbaren Report mit Chart-Beschreibungen",
            backstory=(
                "Daten-Visualisierungs-Spezialist, der Statistiken "
                "in klare Geschichten uebersetzt."
            ),
            llm="ollama/qwen3:8b",
        )

    @task
    def analyze(self) -> CrewTask:
        return CrewTask(
            description="Analysiere die CSV unter: {csv_path}",
            expected_output="Statistische Zusammenfassung: n, mean, std, Korrelationen.",
            agent=self.analyst(),
        )

    @task
    def visualize(self) -> CrewTask:
        return CrewTask(
            description="Erstelle einen Report mit Chart-Beschreibungen.",
            expected_output="Markdown-Report, 300-500 Woerter, mit Chart-Abschnitten.",
            agent=self.visualizer(),
            context=[self.analyze()],
        )

    @crew
    def assemble(self) -> Crew:
        return Crew(
            agents=[self.analyst(), self.visualizer()],
            tasks=[self.analyze(), self.visualize()],
            process=CrewProcess.SEQUENTIAL,
            verbose=False,
        )
