/*
 * 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.project;

import de.sormuras.bach.tool.Javac;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
import java.util.stream.Collectors;

/** A set of module units and tool arguments. */
public final class MainSources {

  public static MainSources of() {
    return new MainSources(Map.of(), Javac.of());
  }

  private final Map<String, ModuleSource> units;
  private final Javac javac;

  public MainSources(Map<String, ModuleSource> units, Javac javac) {
    this.units = Map.copyOf(units);
    this.javac = javac;
  }

  public Map<String, ModuleSource> units() {
    return units;
  }

  public Javac javac() {
    return javac;
  }

  public List<String> unitNames() {
    return units.keySet().stream().sorted().collect(Collectors.toUnmodifiableList());
  }

  public Optional<ModuleSource> unit(String name) {
    return Optional.ofNullable(units.get(name));
  }

  public MainSources with(ModuleSource unit, ModuleSource... more) {
    var mergedUnits = new TreeMap<>(units);
    mergedUnits.put(unit.module().name(), unit);
    for (var m : more) mergedUnits.put(m.module().name(), unit);
    return new MainSources(mergedUnits, javac);
  }

  public MainSources with(Javac javac) {
    return new MainSources(units, javac);
  }
}

@@ -698,16 +698,54 @@
 .Javac;%0A
+import de.sormuras.bach.tool.Javadoc;%0A
 import j
@@ -1036,16 +1036,30 @@
 vac.of()
+, Javadoc.of()
 );%0A  %7D%0A%0A
@@ -1135,16 +1135,49 @@
 c javac;
+%0A  private final Javadoc javadoc;
 %0A%0A  publ
@@ -1227,32 +1227,49 @@
 its, Javac javac
+, Javadoc javadoc
 ) %7B%0A    this.uni
@@ -1308,32 +1308,60 @@
 .javac = javac;%0A
+    this.javadoc = javadoc;%0A
   %7D%0A%0A  public Ma
@@ -1457,32 +1457,86 @@
 urn javac;%0A  %7D%0A%0A
+  public Javadoc javadoc() %7B%0A    return javadoc;%0A  %7D%0A%0A
   public List%3CSt
@@ -2020,24 +2020,33 @@
 Units, javac
+, javadoc
 );%0A  %7D%0A%0A  pu
@@ -2121,16 +2121,126 @@
 s, javac
+, javadoc);%0A  %7D%0A%0A  public MainSources with(Javadoc javadoc) %7B%0A    return new MainSources(units, javac, javadoc
 );%0A  %7D%0A%7D

Extend main sources with javadoc call