"""ASV benchmarks for legacy plan removal overhead regression guard.

Ensures that deprecation warnings in legacy plan classes introduce
negligible overhead to instantiation paths.
"""

from __future__ import annotations

import warnings
from unittest.mock import MagicMock


class LegacyPlanServiceSuite:
    """Benchmark suite for deprecated PlanService instantiation."""

    timeout = 30

    def setup(self) -> None:
        """Prepare mock dependencies for PlanService."""
        self.mock_settings = MagicMock()
        self.mock_settings.database_url = "sqlite:///:memory:"
        self.mock_uow = MagicMock()

    def time_plan_service_instantiation(self) -> None:
        """Time PlanService instantiation (includes deprecation warning)."""
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", DeprecationWarning)
            from cleveragents.application.services.plan_service import PlanService

            PlanService(
                settings=self.mock_settings,
                unit_of_work=self.mock_uow,
            )

    def time_lifecycle_service_instantiation(self) -> None:
        """Time PlanLifecycleService instantiation (no deprecation)."""
        from cleveragents.application.services.plan_lifecycle_service import (
            PlanLifecycleService,
        )

        PlanLifecycleService(settings=self.mock_settings)


class LegacyRepositorySuite:
    """Benchmark suite for deprecated repository instantiation."""

    timeout = 30

    def setup(self) -> None:
        """Prepare mock session."""
        self.mock_session = MagicMock()

    def time_plan_repository_instantiation(self) -> None:
        """Time PlanRepository instantiation (includes deprecation)."""
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", DeprecationWarning)
            from cleveragents.infrastructure.database.repositories import (
                PlanRepository,
            )

            PlanRepository(self.mock_session)

    def time_change_repository_instantiation(self) -> None:
        """Time ChangeRepository instantiation (includes deprecation)."""
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", DeprecationWarning)
            from cleveragents.infrastructure.database.repositories import (
                ChangeRepository,
            )

            ChangeRepository(self.mock_session)

    def time_lifecycle_plan_repository_instantiation(self) -> None:
        """Time LifecyclePlanRepository instantiation (no deprecation)."""
        from cleveragents.infrastructure.database.repositories import (
            LifecyclePlanRepository,
        )

        LifecyclePlanRepository(session_factory=lambda: self.mock_session)


class LegacyCLIWrapperSuite:
    """Benchmark suite for deprecated CLI wrapper overhead."""

    timeout = 30

    def time_deprecation_warning_overhead(self) -> None:
        """Time the overhead of issuing a single DeprecationWarning."""
        with warnings.catch_warnings():
            warnings.simplefilter("ignore", DeprecationWarning)
            warnings.warn(
                "benchmark deprecation test",
                DeprecationWarning,
                stacklevel=1,
            )
