from abc import ABC, abstractmethod
from logging import Logger
from typing import override

from test_automation_suite.core.context import Context
from test_automation_suite.core.reboot import ensure_booted_graphics_mode
from test_automation_suite.core.task import Step, StepResult, Task


class Check(Task, ABC):
    arg: str | None = None

    @abstractmethod
    @override
    def steps(self) -> list[Step]:
        return [*super().steps(), self.step_prepare_graphics_mode]

    def step_prepare_graphics_mode(self, _context: Context, logger: Logger) -> StepResult:
        if self.arg in ["igpu", "on-demand", "dgpu", "intel", "nvidia"]:
            info = ensure_booted_graphics_mode(self.arg)
            for error in info:
                logger.error("Error during ensure_booted_graphics_mode: %s", error)
            return StepResult(
                success=info.ensured,
                needs_reboot=info.reboot_needed,
            )
        return StepResult(success=True)
