content: /*
   * Copyright (C) 2021-2025 Lightbend Inc. <https://www.lightbend.com>
   */
  
  package akkajavasdk.components.actions.echo;
  
  import akka.javasdk.annotations.Component;
  import akka.javasdk.client.ComponentClient;
  import akka.javasdk.timedaction.TimedAction;
  import akkajavasdk.StaticTestBuffer;
  import java.util.List;
  import java.util.concurrent.Executor;
  
  @Component(id = "echo")
  public class EchoAction extends TimedAction {
  
    private boolean constructedOnVt = Thread.currentThread().isVirtual();
  
    // executor and component client just to cover that they can be injected, not really used here
    public EchoAction(ComponentClient componentClient, Executor virtualThreadExecutor) {}
  
    public Effect emptyMessage() {
      StaticTestBuffer.addValue("echo-action", "empty");
      return effects().done();
    }
  
    public Effect stringMessage(String msg) {
      if (msg.equals("check-if-virtual-thread")) {
        StaticTestBuffer.addValue(
            "echo-action",
            "is-virtual-thread:" + (Thread.currentThread().isVirtual() && constructedOnVt));
      } else {
        StaticTestBuffer.addValue("echo-action", msg);
      }
      return effects().done();
    }
  
    public Effect stringMessages(List<String> msg) {
      StaticTestBuffer.addValue("echo-action", String.join(" ", msg));
      return effects().done();
    }
  
    public record SomeCommand(String text) {}
  
    public Effect commandMessages(List<SomeCommand> msg) {
      StaticTestBuffer.addValue(
          "echo-action", String.join(" ", msg.stream().map(c -> c.text).toList()));
      return effects().done();
    }
  }
  