package asp.gencay;

import asp.UnifyWithoutWildcards;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.scope.JavaClassName;
import de.dhbwstuttgart.sat.asp.Clingo;
import de.dhbwstuttgart.sat.asp.parser.ASPParser;
import de.dhbwstuttgart.sat.asp.writer.ASPFactory;
import de.dhbwstuttgart.sat.asp.writer.ASPGencayFactory;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.visual.ResultSetPrinter;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;

public class GeneratorTest extends UnifyWithoutWildcards{
    @Test
    public void simple() throws ClassNotFoundException {
        ConstraintSet<Pair> testSet = new ConstraintSet<>();
        List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
        List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
        RefType t1 = new RefType(new JavaClassName("java.util.List"), list1, new NullToken());
        RefType t2 = new RefType(new JavaClassName("java.util.List"), list2, new NullToken());
        testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
        String resultSet = ASPGencayFactory.generateASP(testSet,
                new HashSet<>(Arrays.asList(ASTFactory.createClass(List.class))));
        System.out.println(resultSet);
    }

    @Test
    public void matrix() throws ClassNotFoundException {
        ConstraintSet<Pair> testSet = new ConstraintSet<>();
        List<RefTypeOrTPHOrWildcardOrGeneric> list1 = Arrays.asList(TypePlaceholder.fresh(new NullToken()));
        List<RefTypeOrTPHOrWildcardOrGeneric> list2 = Arrays.asList(TypePlaceholder.fresh(new NullToken()),TypePlaceholder.fresh(new NullToken()));
        RefType t1 = new RefType(new JavaClassName("asp.UnifyWithoutWildcards$Matrix"), list1, new NullToken());
        RefType t2 = new RefType(new JavaClassName("java.util.HashMap"), list2, new NullToken());
        testSet.addUndConstraint(new Pair(t1, t2, PairOperator.SMALLERDOT));
        String resultSet = ASPGencayFactory.generateASP(testSet, this.getFC());
        System.out.println(resultSet);
    }

    private Collection<ClassOrInterface> getFC() {
        Set<ClassOrInterface> ret = new HashSet<>();
        ret.add(ASTFactory.createClass(Matrix.class));
        //ret.add(ASTFactory.createObjectClass());
        //ret.add(ASTFactory.createClass(java.util.List.class));
        return ret;
    }
}

class Matrix extends Vector<Vector<Integer>> {}