from gateway_core.application.ports.RebootPort import RebootPort
from gateway_core.domain.Reboot import RebootDto, RebootType, RebootEntity
from gateway_core.domain.errors import NotSupportedError
from gateway_platform.logind.LogindManagerClient import LogindManagerClient


class LogindRebootPortAdapter(RebootPort):
    def __init__(self, *, isArmed: bool = False, client: LogindManagerClient = None) -> None:
        self.client = client
        self.isArmed = isArmed

    async def triggerReboot(self, dto: RebootDto) -> None:
        if dto.type != RebootType.hard or dto.entity != RebootEntity.os:
            raise NotSupportedError("logind supports only hard/OS reboot")

        if not self.isArmed:
            return

        await self.client.reboot()
