Initialize ChatGptClient with Configuration param

The ChatGptClient* classes are now initialized with a Configuration
parameter, streamlining the code by eliminating the need to pass it with
each `ask` method call.

Change-Id: Iea77711825d8a4b859fc6db0d5788f3ab70a839d
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 b752f28..440401f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
@@ -142,7 +142,7 @@
             return new ChatGptResponseContent(String.format(SPLIT_REVIEW_MSG, config.getMaxReviewLines()));
         }
 
-        return chatGptClient.ask(config, changeSetData, change, patchSet);
+        return chatGptClient.ask(changeSetData, change, patchSet);
     }
 
     private Integer getReviewScore() {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/chatgpt/ChatGptClient.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/chatgpt/ChatGptClient.java
index d33e476..f6e10fb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/chatgpt/ChatGptClient.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/chatgpt/ChatGptClient.java
@@ -1,6 +1,7 @@
 package com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.chatgpt;
 
 import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
+import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.ClientBase;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.*;
 
 import lombok.Getter;
@@ -14,11 +15,15 @@
 import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
 
 @Slf4j
-abstract public class ChatGptClient {
+abstract public class ChatGptClient extends ClientBase {
     protected boolean isCommentEvent = false;
     @Getter
     protected String requestBody;
 
+    public ChatGptClient(Configuration config) {
+        super(config);
+    }
+
     protected ChatGptResponseContent extractContent(Configuration config, String body) throws Exception {
         if (config.getGptStreamOutput() && !isCommentEvent) {
             StringBuilder finalContent = new StringBuilder();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/interfaces/client/api/chatgpt/IChatGptClient.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/interfaces/client/api/chatgpt/IChatGptClient.java
index 50f8517..dc3fc14 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/interfaces/client/api/chatgpt/IChatGptClient.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/interfaces/client/api/chatgpt/IChatGptClient.java
@@ -6,7 +6,7 @@
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.data.ChangeSetData;
 
 public interface IChatGptClient {
-    ChatGptResponseContent ask(Configuration config, ChangeSetData changeSetData, GerritChange change, String patchSet)
+    ChatGptResponseContent ask(ChangeSetData changeSetData, GerritChange change, String patchSet)
             throws Exception;
     String getRequestBody();
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptClientStateful.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptClientStateful.java
index 3138063..3594ca2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptClientStateful.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/chatgpt/ChatGptClientStateful.java
@@ -19,17 +19,12 @@
 
     @VisibleForTesting
     @Inject
-    public ChatGptClientStateful(PluginDataHandlerProvider pluginDataHandlerProvider) {
-        super();
+    public ChatGptClientStateful(Configuration config, PluginDataHandlerProvider pluginDataHandlerProvider) {
+        super(config);
         this.pluginDataHandlerProvider = pluginDataHandlerProvider;
     }
 
-    public ChatGptResponseContent ask(
-            Configuration config,
-            ChangeSetData changeSetData,
-            GerritChange change,
-            String patchSet
-    ) {
+    public ChatGptResponseContent ask(ChangeSetData changeSetData, GerritChange change, String patchSet) {
         isCommentEvent = change.getIsCommentEvent();
         String changeId = change.getFullChangeId();
         log.info("Processing STATEFUL ChatGPT Request with changeId: {}, Patch Set: {}", changeId, patchSet);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/chatgpt/ChatGptClientStateless.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/chatgpt/ChatGptClientStateless.java
index 6c75c6e..9e8ec57 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/chatgpt/ChatGptClientStateless.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/chatgpt/ChatGptClientStateless.java
@@ -1,6 +1,8 @@
 package com.googlesource.gerrit.plugins.chatgpt.mode.stateless.client.api.chatgpt;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.net.HttpHeaders;
+import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.chatgpt.ChatGptClient;
@@ -32,8 +34,14 @@
 
     private final HttpClientWithRetry httpClientWithRetry = new HttpClientWithRetry();
 
-    public ChatGptResponseContent ask(Configuration config, ChangeSetData changeSetData, GerritChange change,
-                                      String patchSet) throws Exception {
+    @VisibleForTesting
+    @Inject
+    public ChatGptClientStateless(Configuration config) {
+        super(config);
+    }
+
+    public ChatGptResponseContent ask(ChangeSetData changeSetData, GerritChange change, String patchSet)
+            throws Exception {
         isCommentEvent = change.getIsCommentEvent();
         String changeId = change.getFullChangeId();
         log.info("Processing STATELESS ChatGPT Request with changeId: {}, Patch Set: {}", changeId, patchSet);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java
index 34d5d35..cfee169 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java
@@ -385,8 +385,8 @@
 
     private IChatGptClient getChatGptClient() {
         return switch (config.getGptMode()) {
-            case stateful -> new ChatGptClientStateful(pluginDataHandlerProvider);
-            case stateless -> new ChatGptClientStateless();
+            case stateful -> new ChatGptClientStateful(config, pluginDataHandlerProvider);
+            case stateless -> new ChatGptClientStateless(config);
         };
     }
 
diff --git a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/integration/CodeReviewPluginIT.java b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/integration/CodeReviewPluginIT.java
index e61846a..d9d99e8 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/integration/CodeReviewPluginIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/integration/CodeReviewPluginIT.java
@@ -55,7 +55,7 @@
         when(config.getGptModel()).thenReturn(Configuration.DEFAULT_GPT_MODEL);
         when(chatGptPromptStateless.getGptSystemPrompt()).thenReturn(ChatGptPromptStateless.DEFAULT_GPT_SYSTEM_PROMPT);
 
-        ChatGptResponseContent answer = chatGptClient.ask(config, changeSetData, new GerritChange(""), "hello");
+        ChatGptResponseContent answer = chatGptClient.ask(changeSetData, new GerritChange(""), "hello");
         log.info("answer: {}", answer);
         assertNotNull(answer);
     }