import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

// Java 17+. Run HTTP work on your plugin's background executor, not the game thread.
public final class ScreenshareExample {
  public static void main(String[] args) throws Exception {
    String key = System.getenv("SCREENSHARE_API_KEY");
    if (key == null || key.isBlank()) throw new IllegalStateException("Missing server-side API key");
    HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10))
        .followRedirects(HttpClient.Redirect.NEVER).build();
    HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.screenshare.cn/v1/me"))
        .timeout(Duration.ofSeconds(25)).header("Authorization", "Bearer " + key).GET().build();
    HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
    if (response.statusCode() != 200) {
      // Never log the complete request, Authorization, or invitation link.
      throw new IllegalStateException("API status=" + response.statusCode() + " request_id="
          + response.headers().firstValue("X-Request-Id").orElse("unavailable"));
    }
    System.out.println(response.body()); // /me contains credential metadata, not the secret.
    // Parse with your application's JSON library and compare partner_id to trusted config.
  }
}
