package mb.statix.spoofax;

import static mb.nabl2.terms.matching.TermPattern.P;

import java.util.Arrays;
import java.util.concurrent.ExecutionException;

import org.metaborg.util.future.IFuture;
import org.metaborg.util.task.ICancel;
import org.metaborg.util.task.IProgress;

import com.google.inject.Inject;

import mb.nabl2.terms.ITerm;
import mb.p_raffrayi.IUnitResult;
import mb.p_raffrayi.impl.Broker;
import mb.statix.concurrent.IStatixProject;
import mb.statix.concurrent.ProjectResult;
import mb.statix.concurrent.ProjectTypeChecker;
import mb.statix.concurrent.StatixProject;
import mb.statix.concurrent.nameresolution.ScopeImpl;
import mb.statix.scopegraph.Scope;
import mb.statix.solver.IConstraint;
import mb.statix.solver.IState;
import mb.statix.solver.log.IDebugContext;
import mb.statix.solver.persistent.SolverResult;
import mb.statix.spec.Rule;
import mb.statix.spec.Spec;

public class STX_solve_constraint_concurrent extends StatixConstraintPrimitive {

    @Inject public STX_solve_constraint_concurrent() {
        super(STX_solve_constraint_concurrent.class.getSimpleName());
    }

    @Override protected SolverResult solve(Spec spec, IConstraint constraint, IDebugContext debug, IProgress progress,
            ICancel cancel) throws InterruptedException, ExecutionException {
        final IStatixProject project =
                StatixProject.builder().resource("").rule(Rule.of("resolve", Arrays.asList(P.newWld()), constraint)).build();
        final IFuture<IUnitResult<Scope, ITerm, ITerm, ProjectResult>> future = Broker.run("",
                new ProjectTypeChecker(project, spec, debug), new ScopeImpl(), spec.allLabels(), cancel);
        final IUnitResult<Scope, ITerm, ITerm, ProjectResult> result = future.asJavaCompletion().get();
        final SolverResult resultConfig = result.analysis().solveResult();
        final IState.Immutable state = resultConfig.state().withScopeGraph(result.scopeGraph());
        return resultConfig.withState(state);
    }

}

@@ -360,32 +360,73 @@
 yi.IUnitResult;%0A
+import mb.p_raffrayi.impl.AInitialState;%0A
 import mb.p_raff
@@ -574,24 +574,69 @@
 ypeChecker;%0A
+import mb.statix.concurrent.StatixDifferOps;%0A
 import mb.st
@@ -1740,16 +1740,78 @@
 abels(),
+%0A                AInitialState.added(), new StatixDifferOps(),
  cancel)

Fix test evaluation primitive.