from clarabot_nano_common.common.error import log_escape_str
from clarabot_nano.common.request.server_general import AdminDriveAddBackupRoomRequest
from clarabot_nano.server.general.handler.admin.config_update.base import AbstractAdminConfigUpdateServerHandler


class DriveAddBackupRoomHandler(AbstractAdminConfigUpdateServerHandler):
    HANDLER_KEY = AdminDriveAddBackupRoomRequest.TYPE_KEY

    def _create_config_update_request(self) -> dict:
        return {
            "_handler_key": "drive:add-backup-room",
            "path": self.payload.get(AdminDriveAddBackupRoomRequest.PATH),
            "room_id": self.payload.get(AdminDriveAddBackupRoomRequest.TARGET_ROOM_ID),
        }

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