package de.dhbwstuttgart.target.generate;

import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.target.tree.type.TargetType;
import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType;
import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH;
import de.dhbwstuttgart.typeinference.result.ResultPair;
import org.antlr.v4.codegen.model.decl.ContextRuleListIndexedGetterDecl;
import org.jspecify.annotations.NonNull;

import java.util.*;

public class GenericsResultSet extends AbstractSet<GenerateGenerics.Pair> {

    final Set<GenerateGenerics.Pair> backing;
    final IGenerics generics;

    public GenericsResultSet(Set<GenerateGenerics.Pair> backing, IGenerics generics) {
        this.backing = backing == null ? new HashSet<>() : new HashSet<>(backing);
        this.generics = generics;
    }

    public IGenerics getGenerics() {
        return this.generics;
    }

    @Override
    @NonNull
    public Iterator<GenerateGenerics.Pair> iterator() {
        return backing.iterator();
    }

    @Override
    public int size() {
        return backing.size();
    }

    public Optional<GenerateGenerics.Pair> getResultPairFor(TypePlaceholder tph) {
        var tph2 = generics.getEqualType(tph);
        return this.stream().filter(pair -> pair.left.resolve().equals(tph2)).findFirst();
    }
}
