package de.dhbwstuttgart.target.generate;

import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;

import java.util.AbstractList;
import java.util.List;

public class BoundsList extends AbstractList<Bound> {
    private final List<Bound> bounds;
    public final RefTypeOrTPHOrWildcardOrGeneric base;

    public BoundsList(RefTypeOrTPHOrWildcardOrGeneric base, List<Bound> bounds) {
        this.base = base;
        this.bounds = bounds;
    }

    public BoundsList(List<Bound> bounds) {
        this(null, bounds);
    }

    public BoundsList(Bound... bounds) {
        this(null, List.of(bounds));
    }

    @Override
    public Bound get(int index) {
        return bounds.get(index);
    }

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

    @Override
    public boolean equals(Object other) {
        if (!(other instanceof BoundsList right)) return false;
        if (size() != right.size()) return false;
        for (var i = 0; i < size(); i++) {
            var l = get(i);
            var r = right.get(i);
            if (l.isOnMethod() != r.isOnMethod()) return false;
            if (i == size() - 1) {
                if (!(l.bound() instanceof TypePlaceholder)) {
                    if (!(l.bound().equals(r.bound()))) return false;
                }
            }
        }
        return true;
    }
}
