package com.namelessmc.java_api.modules.websend;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.namelessmc.java_api.NamelessException;
import com.namelessmc.java_api.RequestHandler;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.util.*;

public class WebsendAPI {

	private final @NonNull RequestHandler requests;

	public WebsendAPI(@NonNull RequestHandler requests) {
		this.requests = Objects.requireNonNull(requests, "Request handler is null");
	}

	public @NonNull List<WebsendCommand> commands(int serverId) throws NamelessException {
		JsonObject response = this.requests.get("websend/commands","server_id", serverId);
		JsonArray commandsJson = response.getAsJsonArray("commands");
		List<WebsendCommand> commands = new ArrayList<>(commandsJson.size());
		for (JsonElement e : commandsJson) {
			JsonObject commandJson = e.getAsJsonObject();
			int commandId = commandJson.get("id").getAsInt();
			String commandLine = commandJson.get("command").getAsString();
			commands.add(new WebsendCommand(commandId, commandLine));
		}
		return Collections.unmodifiableList(commands);
	}

	public void sendConsoleLog(int serverId, @NonNull Collection<String> lines) throws NamelessException {
		JsonObject body = new JsonObject();
		body.addProperty("server_id", serverId);
		JsonArray content = new JsonArray();
		for (String line : lines) {
			content.add(line);
		}
		body.add("content", content);
		this.requests.post("websend/console", body);
	}

}

@@ -1217,24 +1217,156 @@
 rverId, 
-@NonNull
+Collection%3CString%3E lines) throws NamelessException %7B%0A%09%09sendConsoleLog(serverId, lines, false);%0A%09%7D%0A%0A%09public void sendConsoleLog(int serverId,
  Collect
@@ -1374,32 +1374,55 @@
 on%3CString%3E lines
+, boolean clearPrevious
 ) throws Nameles
@@ -1507,32 +1507,85 @@
 id%22, serverId);%0A
+%09%09body.addProperty(%22clear_previous%22, clearPrevious);%0A
 %09%09JsonArray cont

add sendConsoleLog clearPrevious boolean