package org.implab.gradle.common.sources;

import org.implab.gradle.common.core.lang.Closures;
import org.gradle.api.Action;
import org.gradle.api.NamedDomainObjectProvider;

import groovy.lang.Closure;
import groovy.lang.DelegatesTo;

/**
 * Immutable payload for a newly registered {@link GenericSourceSet}.
 *
 * <p>Used as callback payload for
 * {@link VariantSourcesExtension#whenRegistered(org.gradle.api.Action)} and
 * {@link BuildLayerBinding#whenRegistered(org.gradle.api.Action)}.
 *
 * @param layerName normalized layer name that owns the registration
 * @param sourceSetName source-set name registered in the container
 * @param sourceSet provider of the registered source set (realized later by Gradle on demand)
 */
public record SourceSetRegistration(
        String layerName,
        String sourceSetName,
        NamedDomainObjectProvider<GenericSourceSet> sourceSet) {
    public void configureSourceSet(Action<? super GenericSourceSet> action) {
        sourceSet.configure(action);
    }

    public void configureSourceSet(
            @DelegatesTo(value = GenericSourceSet.class, strategy = Closure.DELEGATE_FIRST) Closure<?> action) {
        configureSourceSet(Closures.action(action));
    }
}
