package org.implab.gradle.variants.sources;

import org.gradle.api.Action;
import org.implab.gradle.common.sources.GenericSourceSet;
import org.implab.gradle.variants.core.Layer;
import org.implab.gradle.variants.core.Variant;
import org.implab.gradle.variants.core.VariantsView;

/**
 * Registry of symbolic source set names produced by sources projection.
 *
 * <p>Identity in this registry is the {@link GenericSourceSet} name assigned
 * by the finalized
 * {@link VariantSourcesExtension#namingPolicy(org.gradle.api.Action)}.
 */
public interface VariantSourcesContext {

   /**
     * Finalized core model.
     */
    VariantsView getVariants();

    /**
     * Derived compile-side view.
     */
    CompileUnitsView getCompileUnits();

    /**
     * Derived role-side view.
     */
    RoleProjectionsView getRoleProjections();

    /**
     * Lazy source set provider service.
     */
    SourceSetMaterializer getSourceSets();

    /**
     * Configures all GenericSourceSets produced from the given layer.
     *
     * The action is applied:
     * - to already materialized source sets of this layer
     * - to all future source sets of this layer
     *
     * <p>For future source sets, selector precedence and registration order are
     * preserved by the materializer.
     *
     * <p>For already materialized source sets, behavior is governed by
     * {@link VariantSourcesExtension#lateConfigurationPolicy(org.gradle.api.Action)}.
     * In warn/allow modes the action is applied as a late imperative step and does
     * not retroactively restore selector precedence.
     */
    void configureLayer(Layer layer, Action<? super GenericSourceSet> action);

    /**
     * Configures all GenericSourceSets produced from the given variant.
     *
     * <p>Late application semantics for already materialized source sets are
     * governed by
     * {@link VariantSourcesExtension#lateConfigurationPolicy(org.gradle.api.Action)}.
     */
    void configureVariant(Variant variant, Action<? super GenericSourceSet> action);

    /**
     * Configures the GenericSourceSet produced from the given compile unit.
     *
     * <p>Late application semantics for already materialized source sets are
     * governed by
     * {@link VariantSourcesExtension#lateConfigurationPolicy(org.gradle.api.Action)}.
     */
    void configureUnit(CompileUnit unit, Action<? super GenericSourceSet> action);

}
