"""Full suite — composes all suites in sequence (fail-fast by default)."""

from __future__ import annotations

from typing import TYPE_CHECKING

from tests.remote.suites.base import BaseSuite, StepStatus, SuiteResult
from tests.remote.suites.clean import CleanSuite
from tests.remote.suites.doctor import DoctorSuite
from tests.remote.suites.inference import InferenceSuite
from tests.remote.suites.install import InstallSuite
from tests.remote.suites.serve import ServeSuite
from tests.remote.suites.uninstall import UninstallSuite
from tests.remote.suites.upgrade import UpgradeSuite

if TYPE_CHECKING:
    from tests.remote.runner import RemoteTestRunner


class FullSuite(BaseSuite):
    name = "full"
    description = "Full customer experience: clean -> install -> doctor -> serve -> inference -> upgrade -> uninstall"

    def __init__(self, *, continue_on_failure: bool = False) -> None:
        self.continue_on_failure = continue_on_failure

    async def execute(self, runner: RemoteTestRunner, result: SuiteResult) -> None:
        sub_suites: list[BaseSuite] = [
            CleanSuite(),
            InstallSuite(),
            DoctorSuite(),
            ServeSuite(),
            InferenceSuite(),
            UpgradeSuite(),
            UninstallSuite(),
        ]

        for suite in sub_suites:
            sub_result = await suite.run(runner, device_name=result.device_name)

            # Merge steps into the parent result, prefixed with suite name
            for step in sub_result.steps:
                step.name = f"{suite.name}/{step.name}"
                result.steps.append(step)

            # Fail-fast: stop on first sub-suite failure unless continue_on_failure
            if not sub_result.success and not self.continue_on_failure:
                self._add_step(
                    result,
                    "fail_fast",
                    f"Stopping after '{suite.name}' failed (use --continue-on-failure to override)",
                    status=StepStatus.SKIPPED,
                )
                break
