package com.github.sormuras.bach.call;

import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.function.IntSupplier;
import java.util.stream.Collectors;

public record JavacCall(List<String> arguments) implements AnyCall<JavacCall> {

  public JavacCall() {
    this(List.of());
  }

  @Override
  public String name() {
    return "javac";
  }

  @Override
  public JavacCall arguments(List<String> arguments) {
    if (this.arguments == arguments) return this;
    return new JavacCall(arguments);
  }

  /** @param directory Specify where to place generated class files */
  public JavacCall withDirectoryForClasses(Path directory) {
    return with("-d", directory);
  }

  public JavacCall withEncoding(Charset charset) {
    return with("-encoding", charset);
  }

  public JavacCall withModule(List<String> modules) {
    return with("--module", String.join(",", modules));
  }

  public JavacCall withModuleSourcePathPatterns(List<String> patterns) {
    var joined =
        patterns.stream()
            .map(pattern -> pattern.replace('/', File.separatorChar))
            .map(pattern -> pattern.replace('\\', File.separatorChar))
            .collect(Collectors.joining(File.pathSeparator));
    return with("--module-source-path", joined);
  }

  public JavacCall withModuleSourcePath(String module, List<Path> paths) {
    var joined = paths.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator));
    return with("--module-source-path", module + '=' + joined);
  }

  public JavacCall withModuleSourcePathSpecifics(Map<String, List<Path>> map) {
    return forEach(map.entrySet(), (c, e) -> c.withModuleSourcePath(e.getKey(), e.getValue()));
  }

  public JavacCall withRelease(IntSupplier release) {
    return withRelease(release.getAsInt());
  }

  public JavacCall withRelease(int release) {
    return with("--release", release);
  }
}

@@ -959,32 +959,132 @@
 modules));%0A  %7D%0A%0A
+  public JavacCall withModulePath(List%3CPath%3E paths) %7B%0A    return with(%22--module-path%22, paths);%0A  %7D%0A%0A
   public JavacCa
@@ -1858,32 +1858,429 @@
 Value()));%0A  %7D%0A%0A
+  public JavacCall withPatchModule(String module, List%3CPath%3E paths) %7B%0A    var joined = paths.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator));%0A    return with(%22--patch-module%22, module + '=' + joined);%0A  %7D%0A%0A  public JavacCall withPatchModules(Map%3CString, List%3CPath%3E%3E map) %7B%0A    return forEach(map.entrySet(), (c, e) -%3E c.withPatchModule(e.getKey(), e.getValue()));%0A  %7D%0A%0A
   public JavacCa

Add more dedicated withers