/*
 * Bach - Java Shell Builder
 * Copyright (C) 2020 Christian Stein
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.sormuras.bach.tool;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.spi.ToolProvider;

/** A tool call configuration. */
public interface Call<T> {

  String name();

  List<Argument> arguments();

  T with(List<Argument> arguments);

  default boolean activated() {
    return !arguments().isEmpty();
  }

  default Optional<ToolProvider> tool() {
    return ToolProvider.findFirst(name());
  }

  default T with(Argument argument, Argument... arguments) {
    var list = new ArrayList<>(arguments());
    list.add(argument);
    if (arguments.length > 0) Collections.addAll(list, arguments);
    return with(list);
  }

  default T with(String option) {
    return with(new Argument(option, List.of()));
  }

  default T with(String option, Object... values) {
    var strings = new ArrayList<String>();
    for (var value : values) strings.add(value.toString());
    return with(new Argument(option, strings));
  }

  default String[] toStringArray() {
    var list = new ArrayList<String>();
    for (var argument : arguments()) {
      list.add(argument.key());
      list.addAll(argument.values());
    }
    return list.toArray(String[]::new);
  }
}

@@ -871,567 +871,2035 @@
 %0A%0A  
-String name();%0A%0A  List%3CArgument%3E arguments();%0A%0A  T with(List%3CArgument%3E arguments);%0A%0A  default boolean activated() %7B%0A    return !arguments().isEmpty();%0A  %7D%0A%0A  default Optional%3CToolProvider%3E tool() %7B%0A    return ToolProvider.findFirst(name());%0A  %7D%0A%0A  default T with(Argument argument, Argument... arguments) %7B%0A    var list = new ArrayList%3C%3E(arguments());%0A    list.add(argument);%0A    if (arguments.length %3E 0) Collections.addAll(list, arguments);%0A    return with(list);%0A  %7D%0A%0A  default T with(String option) %7B%0A    return with(new Argument(option, List.of()));%0A  %7D%0A
+/**%0A   * Return the name of this tool call configuration.%0A   *%0A   * @return A string representation of a tool%0A   * @see #tool()%0A   */%0A  String name();%0A%0A  /**%0A   * Return the arguments of this tool call configuration.%0A   *%0A   * @return A possible empty list of argument instances%0A   */%0A  List%3CArgument%3E arguments();%0A%0A  /**%0A   * Create new instance of a tool call configuration with the given arguments.%0A   *%0A   * @param argument The possible emtpy list of argument objects%0A   */%0A  T with(List%3CArgument%3E arguments);%0A%0A  /**%0A   * Return the activation state of this tool call configuration.%0A   *%0A   * @return %7B@code true%7D if this tool call is to executed, else %7B@code false%7D%0A   */%0A  default boolean activated() %7B%0A    return !arguments().isEmpty();%0A  %7D%0A%0A  /**%0A   * Return a tool provider instance in an optional object.%0A   *%0A   * @return An optional tool provider instance%0A   * @see #name()%0A   */%0A  default Optional%3CToolProvider%3E tool() %7B%0A    return ToolProvider.findFirst(name());%0A  %7D%0A%0A  /**%0A   * Create new call instance with the given additional arguments.%0A   *%0A   * @param argument The first additional argument%0A   * @param arguments The array of more additional arguments%0A   * @return A new call instance with the given arguments%0A   */%0A  default T with(Argument argument, Argument... arguments) %7B%0A    var list = new ArrayList%3C%3E(arguments());%0A    list.add(argument);%0A    if (arguments.length %3E 0) Collections.addAll(list, arguments);%0A    return with(list);%0A  %7D%0A  %0A  /**%0A   * Create new call instance with one additional argument.%0A   *%0A   * @param option The option to used as an additional argument%0A   * @return A new call instance with the given argument%0A   */%0A  default T with(String option) %7B%0A    return with(new Argument(option, List.of()));%0A  %7D%0A  %0A  /**%0A   * Create new call instance with one or more additional arguments.%0A   *%0A   * @param option The option to used as an additional argument%0A   * @param values The possible empty array of additional arguments%0A   * @return A new call instance with the given arguments%0A   */
 %0A  d
@@ -3103,16 +3103,201 @@
 );%0A  %7D%0A%0A
+  /**%0A   * Return the arguments of this tool call configuration as an array of string objects.%0A   *%0A   * @return An array of strings representing the arguments of this tool call.%0A   */%0A
   defaul

Document Call API