from clarabot_nano_common.common.error import log_escape_str

from clarabot_nano.common.request.server_general import AdminAttachDriveRequest
from clarabot_nano.server.general.handler.admin.config_update.base import AbstractAdminConfigUpdateServerHandler


class AttachDriveHandler(AbstractAdminConfigUpdateServerHandler):
    HANDLER_KEY = AdminAttachDriveRequest.TYPE_KEY

    def _create_config_update_request(self) -> dict:
        return {
            "_handler_key": "drive:attach-room",
            "path": self.payload.get(AdminAttachDriveRequest.PATH),
            "room_id": self.payload.get(AdminAttachDriveRequest.TARGET_ROOM_ID),
            "room_blocks": self.payload.get(AdminAttachDriveRequest.ROOM_BLOCKS),
        }

    def _log_message(self) -> str:
        return (
            f"Attach drive at {log_escape_str(self.payload.get(AdminAttachDriveRequest.PATH))} "
            f"to room {self.payload.get(AdminAttachDriveRequest.TARGET_ROOM_ID)}"
        )
