package joptsimple;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class OptionSpecBuilder extends NoArgumentOptionSpec {
   private final OptionParser parser;

   OptionSpecBuilder(OptionParser parser, Collection<String> options, String description) {
      super(options, description);
      this.parser = parser;
      this.attachToParser();
   }

   private void attachToParser() {
      this.parser.recognize(this);
   }

   public ArgumentAcceptingOptionSpec<String> withRequiredArg() {
      ArgumentAcceptingOptionSpec<String> newSpec = new RequiredArgumentOptionSpec(this.options(), this.description());
      this.parser.recognize(newSpec);
      return newSpec;
   }

   public ArgumentAcceptingOptionSpec<String> withOptionalArg() {
      ArgumentAcceptingOptionSpec<String> newSpec = new OptionalArgumentOptionSpec(this.options(), this.description());
      this.parser.recognize(newSpec);
      return newSpec;
   }

   public OptionSpecBuilder requiredIf(String dependent, String... otherDependents) {
      List<String> dependents = new ArrayList();
      dependents.add(dependent);
      Collections.addAll(dependents, otherDependents);
      Iterator i$ = dependents.iterator();

      while(i$.hasNext()) {
         String each = (String)i$.next();
         if (!this.parser.isRecognized(each)) {
            throw new UnconfiguredOptionException(each);
         }

         this.parser.requiredIf(this.options(), dependent);
      }

      return this;
   }

   public OptionSpecBuilder requiredIf(OptionSpec<?> dependent, OptionSpec<?>... otherDependents) {
      this.parser.requiredIf(this.options(), dependent);
      OptionSpec[] arr$ = otherDependents;
      int len$ = otherDependents.length;

      for(int i$ = 0; i$ < len$; ++i$) {
         OptionSpec<?> each = arr$[i$];
         this.parser.requiredIf(this.options(), each);
      }

      return this;
   }
}
