from typing import Callable

from nperipherals_core.model.device import DeviceServiceThread


class HealthCheckInteractor(object):
    def __init__(self, device_service_thread, destroy_func, build_func):
        # type: (DeviceServiceThread, Callable[[], None], Callable[[], None]) -> None

        self.device_service_thread = device_service_thread
        self.destroy_func = destroy_func
        self.build_func = build_func

    def restart_dead_threads(self):
        # type: () -> None

        if self.device_service_thread is not None and not self.device_service_thread.running:
            self.destroy_func()
            self.build_func()
