"""Uninstall suite — clean removal of llmhosts (preserves user models)."""

from __future__ import annotations

from typing import TYPE_CHECKING

from tests.remote.suites.base import BaseSuite, StepStatus, SuiteResult

if TYPE_CHECKING:
    from tests.remote.runner import RemoteTestRunner


class UninstallSuite(BaseSuite):
    name = "uninstall"
    description = "Uninstall llmhosts and verify removal (preserves inference engine and models)"

    async def execute(self, runner: RemoteTestRunner, result: SuiteResult) -> None:
        # Step 1: Uninstall
        r = await runner.run_command("pip uninstall llmhosts -y", timeout=60.0)
        self._add_step(
            result,
            "pip_uninstall",
            "Run pip uninstall llmhosts -y",
            status=StepStatus.PASSED if r.success else StepStatus.FAILED,
            stdout=r.stdout,
            stderr=r.stderr,
            duration_s=r.duration_s,
            error_message="" if r.success else f"Uninstall failed (exit={r.exit_code})",
        )

        # Step 2: Verify command removed
        r = await runner.run_command("llmhosts --version", timeout=15.0)
        command_gone = r.exit_code != 0

        self._add_step(
            result,
            "verify_removed",
            "Verify llmhosts command no longer available",
            status=StepStatus.PASSED if command_gone else StepStatus.FAILED,
            stdout=r.stdout if not command_gone else "Command not found (expected)",
            duration_s=r.duration_s,
            error_message="" if command_gone else "llmhosts command still available after uninstall",
        )

        # Note: We intentionally do NOT remove the inference engine or models.
        # That is user data and should be preserved.
        self._add_step(
            result,
            "preserve_user_data",
            "Note: Inference engine and models preserved (user data)",
            status=StepStatus.PASSED,
        )
