Refactor `DebugMessages` class

The static class `DebugMessages` has been refactored to
`DebugCodeBlocksReview`, which now inherits from a new general-purpose
class `DebugCodeBlocks`.
This refactor aims to:
- Generalize `DebugCodeBlocks` for future use in dynamic config settings
from messages;
- Improve the clarity of the class name;
- Enable the use of localized text.

Change-Id: I545e55803759b69183500bc7ff67af2956560fb9
Signed-off-by: Patrizio <patrizio.gelosi@amarulasolutions.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
index ed40c50..f94323b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
@@ -8,7 +8,7 @@
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritChange;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritClient;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritClientReview;
-import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.messages.DebugMessages;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.messages.DebugCodeBlocksReview;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.patch.comment.GerritCommentRange;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptReplyItem;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptResponseContent;
@@ -34,6 +34,7 @@
     @Getter
     private final IChatGptClient chatGptClient;
     private final Localizer localizer;
+    private final DebugCodeBlocksReview debugCodeBlocksReview;
 
     private GerritCommentRange gerritCommentRange;
     private List<ReviewBatch> reviewBatches;
@@ -55,6 +56,7 @@
         this.clientReviewProvider = clientReviewProvider;
         this.chatGptClient = chatGptClient;
         this.localizer = localizer;
+        debugCodeBlocksReview = new DebugCodeBlocksReview(localizer);
     }
 
     public void review(GerritChange change) throws Exception {
@@ -120,7 +122,7 @@
                 continue;
             }
             if (changeSetData.getDebugMode()) {
-                reply += DebugMessages.getDebugMessage(replyItem, isHidden);
+                reply += debugCodeBlocksReview.getDebugCodeBlock(replyItem, isHidden);
             }
             ReviewBatch batchMap = new ReviewBatch();
             batchMap.setContent(reply);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/ClientMessage.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/ClientMessage.java
index 6370782..1d545f5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/ClientMessage.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/ClientMessage.java
@@ -18,6 +18,7 @@
 
     private final Pattern botMentionPattern;
     private final ClientCommands clientCommands;
+    private final DebugCodeBlocksReview debugCodeBlocksReview;
 
     @Getter
     private String message;
@@ -26,6 +27,7 @@
         super(config);
         botMentionPattern = getBotMentionPattern();
         clientCommands = new ClientCommands(config, changeSetData, localizer);
+        debugCodeBlocksReview = new DebugCodeBlocksReview(localizer);
     }
 
     public ClientMessage(Configuration config, ChangeSetData changeSetData, String message, Localizer localizer) {
@@ -60,8 +62,8 @@
         return this;
     }
 
-    public ClientMessage removeDebugMessages() {
-        message = DebugMessages.removeDebugMessages(message);
+    public ClientMessage removeDebugCodeBlocks() {
+        message = debugCodeBlocksReview.removeDebugCodeBlocks(message);
         return this;
     }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/DebugCodeBlocks.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/DebugCodeBlocks.java
new file mode 100644
index 0000000..4cb2491
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/DebugCodeBlocks.java
@@ -0,0 +1,32 @@
+package com.googlesource.gerrit.plugins.chatgpt.mode.common.client.messages;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static com.googlesource.gerrit.plugins.chatgpt.utils.TextUtils.*;
+
+public class DebugCodeBlocks {
+    protected final String commentOpening;
+    protected final Pattern debugMessagePattern;
+
+    public DebugCodeBlocks(String openingTitle) {
+        commentOpening = CODE_DELIMITER_BEGIN + openingTitle + "\n";
+        debugMessagePattern = Pattern.compile("\\s+" + CODE_DELIMITER +"\\s*" + openingTitle + ".*" +
+                CODE_DELIMITER + "\\s*", Pattern.DOTALL);
+    }
+
+    public String removeDebugCodeBlocks(String message) {
+        Matcher debugMessagematcher = debugMessagePattern.matcher(message);
+        return debugMessagematcher.replaceAll("");
+    }
+
+    protected String getDebugCodeBlock(List<String> panelItems) {
+        return joinWithNewLine(new ArrayList<>() {{
+            add(commentOpening);
+            addAll(panelItems);
+            add(CODE_DELIMITER);
+        }});
+    }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/DebugCodeBlocksReview.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/DebugCodeBlocksReview.java
new file mode 100644
index 0000000..2c2f607
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/DebugCodeBlocksReview.java
@@ -0,0 +1,23 @@
+package com.googlesource.gerrit.plugins.chatgpt.mode.common.client.messages;
+
+import com.googlesource.gerrit.plugins.chatgpt.localization.Localizer;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptReplyItem;
+
+import java.util.List;
+
+import static com.googlesource.gerrit.plugins.chatgpt.utils.TextUtils.prettyStringifyObject;
+
+public class DebugCodeBlocksReview extends DebugCodeBlocks {
+    private static final String HIDDEN_REPLY = "hidden: %s";
+
+    public DebugCodeBlocksReview(Localizer localizer) {
+        super(localizer.getText("message.debugging.review.title"));
+    }
+
+    public String getDebugCodeBlock(ChatGptReplyItem replyItem, boolean isHidden) {
+        return super.getDebugCodeBlock(List.of(
+                String.format(HIDDEN_REPLY, isHidden),
+                prettyStringifyObject(replyItem)
+        ));
+    }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/DebugMessages.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/DebugMessages.java
deleted file mode 100644
index ef63ad8..0000000
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/messages/DebugMessages.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.googlesource.gerrit.plugins.chatgpt.mode.common.client.messages;
-
-import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptReplyItem;
-
-import java.util.ArrayList;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import static com.googlesource.gerrit.plugins.chatgpt.utils.TextUtils.*;
-
-public class DebugMessages {
-    private static final String OPENING_TITLE = "DEBUGGING DETAILS";
-    private static final String COMMENT_OPENING = CODE_DELIMITER_BEGIN + OPENING_TITLE + "\n";
-    private static final String HIDDEN_REPLY = "hidden: %s";
-    private static final Pattern DEBUG_MESSAGE_PATTERN = Pattern.compile("\\s+" + CODE_DELIMITER +"\\s*" +
-                    OPENING_TITLE + ".*" + CODE_DELIMITER + "\\s*", Pattern.DOTALL);
-
-    public static String getDebugMessage(ChatGptReplyItem replyItem, boolean isHidden) {
-        return joinWithNewLine(new ArrayList<>() {{
-            add(COMMENT_OPENING);
-            add(String.format(HIDDEN_REPLY, isHidden));
-            add(prettyStringifyObject(replyItem));
-            add(CODE_DELIMITER);
-        }});
-    }
-
-    public static String removeDebugMessages(String message) {
-        Matcher debugMessagematcher = DEBUG_MESSAGE_PATTERN.matcher(message);
-        return debugMessagematcher.replaceAll("");
-    }
-}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptComment.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptComment.java
index f34e611..fccc1a9 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptComment.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptComment.java
@@ -24,7 +24,7 @@
     protected String getCleanedMessage(GerritComment commentProperty) {
         commentMessage = new ClientMessage(config, changeSetData, commentProperty.getMessage(), localizer);
         if (isFromAssistant(commentProperty)) {
-            commentMessage.removeDebugMessages();
+            commentMessage.removeDebugCodeBlocks();
         }
         else {
             commentMessage.removeMentions().parseRemoveCommands();
diff --git a/src/main/resources/localization/localTexts.properties b/src/main/resources/localization/localTexts.properties
index 512f858..00c5f06 100644
--- a/src/main/resources/localization/localTexts.properties
+++ b/src/main/resources/localization/localTexts.properties
@@ -1,3 +1,4 @@
 system.message.prefix=SYSTEM MESSAGE:
 message.empty.review=No update to show for this Change Set
 message.debugging.functionalities.disabled=Message Debugging functionalities are disabled
+message.debugging.review.title=DEBUGGING DETAILS