"""ASV benchmarks for TDD Issue #554 — session list CLI throughput.

Measures the performance of the session list CLI command path to establish
a baseline before and after the DI bug fix.  Uses a mocked service so the
benchmark isolates CLI/rendering overhead from database I/O.
"""

from __future__ import annotations

from unittest.mock import MagicMock

from benchmarks._session_bench_common import mock_session, runner
from cleveragents.cli.commands import session as session_mod
from cleveragents.cli.commands.session import app as session_app


class TDDSessionListDISuite:
    """Benchmark session list command throughput (TDD issue #554 baseline)."""

    def setup(self) -> None:
        self._svc = MagicMock()
        # Use deterministic, unique session IDs for reproducible benchmarks.
        self._svc.list.return_value = [
            mock_session(
                session_id=f"01HXYZ{i:020d}",
                actor_name=f"openai/gpt-{i}",
            )
            for i in range(50)
        ]
        session_mod._service = self._svc

    def teardown(self) -> None:
        session_mod._service = None

    def time_list_rich(self) -> None:
        """Benchmark listing sessions with default rich format."""
        runner.invoke(session_app, ["list"])

    def time_list_json(self) -> None:
        """Benchmark listing sessions with JSON format."""
        runner.invoke(session_app, ["list", "--format", "json"])

    def time_list_empty(self) -> None:
        """Benchmark listing with no sessions."""
        self._svc.list.return_value = []
        runner.invoke(session_app, ["list"])
        # Restore for next benchmark (deterministic IDs).
        self._svc.list.return_value = [
            mock_session(
                session_id=f"01HXYZ{i:020d}",
                actor_name=f"openai/gpt-{i}",
            )
            for i in range(50)
        ]
