from clarabot_nano.common.core.message import MSG_TYPE_GATEWAY_LOGOUT, MSG_TYPE_REQUEST_CONFIG_RESET
from clarabot_nano.control.client import WxCoreInterface
from clarabot_nano.control.nano.base import (
    NanoRequestProgressDialog,
    GatewayNanoRequestProgressStep,
    CoreNanoRequestProgressStep,
    AbstractNanoRequestProgressStep,
)


class ClearInitConfigStep(AbstractNanoRequestProgressStep):
    def text(self) -> str:
        return gettext("Remove init config marker")

    def request(self, core_interface: WxCoreInterface):
        core_interface.get_init_setup_path().unlink(missing_ok=True)


class ResetProgressDialog(NanoRequestProgressDialog):
    def __init__(self, core_interface: WxCoreInterface, parent):
        NanoRequestProgressDialog.__init__(
            self,
            core_interface,
            parent,
            gettext("Resetting Nano instance..."),
            [
                GatewayNanoRequestProgressStep(
                    gettext("Logging out..."), [MSG_TYPE_GATEWAY_LOGOUT, b""], "logout successful"
                ),
                CoreNanoRequestProgressStep(gettext("Resetting config..."), [MSG_TYPE_REQUEST_CONFIG_RESET, b""]),
                ClearInitConfigStep(),
            ],
            gettext("Nano instance has been successfully reset!"),
        )
