from clarabot_nano.common.crypto.admin_password import ADMIN_PASSWORD_CONTEXT
from clarabot_nano.core.config.update.base import AbstractRemoteConfigUpdateHandler


class UpdateAdminPassword(AbstractRemoteConfigUpdateHandler):
    HANDLER_KEY = "admin_password"

    def _execute(self, data: dict):
        self._c["admin_password"] = ADMIN_PASSWORD_CONTEXT.hash(data["admin_password"])

    def _describe_change(self, old_config: dict, new_config: dict, data: dict) -> str:
        return "Nano admin password changed"  # logging it would be a security risk
