package org.implab.gradle.variants.derived;

import java.util.Optional;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.implab.gradle.variants.core.Layer;
import org.implab.gradle.variants.core.Role;
import org.implab.gradle.variants.core.Variant;

@NonNullByDefault
public interface CompileUnitsView {
    Set<CompileUnit> getUnits();

    Set<CompileUnit> getUnitsForVariant(Variant variant);

    Optional<CompileUnit> findUnit(Variant variant, Layer layer);

    default CompileUnit getUnit(Variant variant, Layer layer) {
        return findUnit(variant, layer)
                .orElseThrow(() -> new IllegalArgumentException(
                        "Compile unit for variant '" + variant.getName()
                                + "' and layer '" + layer.getName() + "' not found"));
    }

    boolean contains(Variant variant, Layer layer);

    /**
     * In which logical roles this compile unit participates.
     */
    Set<Role> getRoles(CompileUnit unit);
}