package jetbrains.mps.make.generator;

/*Generated by MPS */

import jetbrains.mps.make.facet.IFacet;
import java.util.List;
import jetbrains.mps.make.facet.ITarget;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.make.resources.IPropertiesPersistence;
import jetbrains.mps.make.facet.ITargetEx;
import jetbrains.mps.make.script.IJob;
import jetbrains.mps.make.script.IResult;
import jetbrains.mps.make.resources.IResource;
import jetbrains.mps.make.script.IJobMonitor;
import jetbrains.mps.make.resources.IPropertiesAccessor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.mps.openapi.util.ProgressMonitor;
import jetbrains.mps.make.script.IConfig;
import jetbrains.mps.baseLanguage.tuples.runtime.Tuples;
import jetbrains.mps.make.script.IPropertiesPool;
import jetbrains.mps.baseLanguage.tuples.runtime.MultiTuple;
import java.util.stream.IntStream;
import org.junit.Assert;
import java.util.Map;
import jetbrains.mps.internal.collections.runtime.MapSequence;

public class Generator__Facet extends IFacet.Stub {
  private List<ITarget> targets = ListSequence.fromList(new ArrayList<ITarget>());
  private IFacet.Name name = new IFacet.Name("jetbrains.mps.make.tests.Generator_");
  public Generator__Facet() {
    ListSequence.fromList(targets).addElement(new Target_Configure());
    ListSequence.fromList(targets).addElement(new Target_Generate());
  }
  public Iterable<ITarget> targets() {
    return targets;
  }
  public Iterable<IFacet.Name> optional() {
    return null;
  }
  public Iterable<IFacet.Name> required() {
    return Sequence.fromArray(new IFacet.Name[]{new IFacet.Name("jetbrains.mps.make.tests.Maker_")});
  }
  public Iterable<IFacet.Name> extended() {
    return null;
  }
  public IFacet.Name getName() {
    return this.name;
  }
  public IPropertiesPersistence propertiesPersistence() {
    return new TargetProperties();
  }
  public static class Target_Configure implements ITargetEx {
    private static final ITarget.Name name = new ITarget.Name("jetbrains.mps.make.tests.Generator_.Configure");
    public Target_Configure() {
    }
    public IJob createJob() {
      return new IJob.Stub() {
        @Override
        public IResult execute(final Iterable<IResource> rawInput, final IJobMonitor monitor, final IPropertiesAccessor pa, @NotNull final ProgressMonitor progressMonitor) {
          Iterable<IResource> _output_j0fmyu_a0a = null;
          final Iterable<IResource> input = (Iterable) (Iterable) rawInput;
          switch (0) {
            case 0:
              vars(pa.global()).value("uninitialized");
            default:
              progressMonitor.done();
              return new IResult.SUCCESS(_output_j0fmyu_a0a);
          }
        }
      };
    }
    public IConfig createConfig() {
      return null;
    }
    public Iterable<ITarget.Name> notAfter() {
      return null;
    }
    public Iterable<ITarget.Name> after() {
      return null;
    }
    public Iterable<ITarget.Name> notBefore() {
      return null;
    }
    public Iterable<ITarget.Name> before() {
      return null;
    }
    public ITarget.Name getName() {
      return name;
    }
    public boolean isOptional() {
      return false;
    }
    public boolean requiresInput() {
      return false;
    }
    public boolean producesOutput() {
      return false;
    }
    public Iterable<Class<? extends IResource>> expectedInput() {
      List<Class<? extends IResource>> rv = ListSequence.fromList(new ArrayList<Class<? extends IResource>>());
      return rv;
    }
    public Iterable<Class<? extends IResource>> expectedOutput() {
      return null;
    }
    public <T> T createParameters(Class<T> cls) {
      return cls.cast(new Variables());
    }
    public <T> T createParameters(Class<T> cls, T copyFrom) {
      T t = createParameters(cls);
      if (t != null) {
        ((Tuples._1) t).assign((Tuples._1) copyFrom);
      }
      return t;
    }
    public static Variables vars(IPropertiesPool ppool) {
      return ppool.properties(name, Variables.class);
    }
    public static class Variables extends MultiTuple._1<String> {
      public Variables() {
        super();
      }
      public Variables(String value) {
        super(value);
      }
      public String value(String value) {
        return super._0(value);
      }
      public String value() {
        return super._0();
      }
    }
  }
  public static class Target_Generate implements ITargetEx {
    private static final ITarget.Name name = new ITarget.Name("jetbrains.mps.make.tests.Generator_.Generate");
    public Target_Generate() {
    }
    public IJob createJob() {
      return new IJob.Stub() {
        @Override
        public IResult execute(final Iterable<IResource> rawInput, final IJobMonitor monitor, final IPropertiesAccessor pa, @NotNull final ProgressMonitor progressMonitor) {
          Iterable<IResource> _output_j0fmyu_a0b = null;
          final Iterable<IResource> input = (Iterable) (Iterable) rawInput;
          progressMonitor.start("", IntStream.of(1000).sum());
          switch (0) {
            case 0:
              Assert.assertEquals("uninitialized", Target_Configure.vars(pa.global()).value());
              final ProgressMonitor subProgress_b0a0b = progressMonitor.subTask(1000);
              subProgress_b0a0b.start("GENERATE", 100);
              Target_Configure.vars(pa.global()).value("VALUE");
              for (IResource resource : input) {
                _output_j0fmyu_a0b = Sequence.fromIterable(_output_j0fmyu_a0b).concat(Sequence.fromIterable(Sequence.<IResource>singleton(resource)));
              }
              subProgress_b0a0b.advance(50);
              subProgress_b0a0b.done();
              _output_j0fmyu_a0b = Sequence.fromIterable(_output_j0fmyu_a0b).concat(Sequence.fromIterable(input));
              return new IResult.SUCCESS(_output_j0fmyu_a0b);
            default:
              progressMonitor.done();
              return new IResult.SUCCESS(_output_j0fmyu_a0b);
          }
        }
      };
    }
    public IConfig createConfig() {
      return null;
    }
    public Iterable<ITarget.Name> notAfter() {
      return null;
    }
    public Iterable<ITarget.Name> after() {
      return Sequence.fromArray(new ITarget.Name[]{new ITarget.Name("jetbrains.mps.make.tests.Generator_.Configure")});
    }
    public Iterable<ITarget.Name> notBefore() {
      return null;
    }
    public Iterable<ITarget.Name> before() {
      return Sequence.fromArray(new ITarget.Name[]{new ITarget.Name("jetbrains.mps.make.tests.Maker_.Make")});
    }
    public ITarget.Name getName() {
      return name;
    }
    public boolean isOptional() {
      return false;
    }
    public boolean requiresInput() {
      return false;
    }
    public boolean producesOutput() {
      return true;
    }
    public Iterable<Class<? extends IResource>> expectedInput() {
      List<Class<? extends IResource>> rv = ListSequence.fromList(new ArrayList<Class<? extends IResource>>());
      return rv;
    }
    public Iterable<Class<? extends IResource>> expectedOutput() {
      return null;
    }
    public <T> T createParameters(Class<T> cls) {
      return null;
    }
    public <T> T createParameters(Class<T> cls, T copyFrom) {
      T t = createParameters(cls);
      return t;
    }
  }
  public static class TargetProperties implements IPropertiesPersistence {
    public TargetProperties() {
    }
    public void storeValues(Map<String, String> store, IPropertiesPool properties) {
      {
        ITarget.Name name = new ITarget.Name("jetbrains.mps.make.tests.Generator_.Configure");
        if (properties.hasProperties(name)) {
          Target_Configure.Variables props = properties.properties(name, Target_Configure.Variables.class);
          MapSequence.fromMap(store).put("jetbrains.mps.make.tests.Generator_.Configure.value", String.valueOf(props.value()));
        }
      }
    }
    public void loadValues(Map<String, String> store, IPropertiesPool properties) {
      try {
        {
          ITarget.Name name = new ITarget.Name("jetbrains.mps.make.tests.Generator_.Configure");
          Target_Configure.Variables props = properties.properties(name, Target_Configure.Variables.class);
          if (MapSequence.fromMap(store).containsKey("jetbrains.mps.make.tests.Generator_.Configure.value")) {
            props.value(String.valueOf(MapSequence.fromMap(store).get("jetbrains.mps.make.tests.Generator_.Configure.value")));
          }
        }
      } catch (RuntimeException re) {
      }
    }
  }
}
