package org.implab.gradle.variants.artifacts;

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

import groovy.lang.Closure;

/**
 * Project-level DSL entry point for declaring outgoing artifacts per variant.
 *
 * <p>A variant represents one external outgoing contract. Slots declared inside a variant represent
 * artifact sets within that contract. One slot is expected to materialize to one published artifact.
 */
public interface VariantArtifactsExtension {
    /**
     * Configures artifact slots of the named variant.
     *
     * @param variantName variant name
     * @param action variant artifact declaration
     */
    void variant(String variantName, Action<? super VariantArtifactsSpec> action);

    default void variant(String variantName, Closure<?> closure) {
        variant(variantName, Closures.action(closure));
    }

    /**
     * Registers a callback invoked with the finalized artifact model.
     *
     * @param action finalized-model callback
     */
    void whenFinalized(Action<? super VariantArtifactsContext> action);

    default void whenFinalized(Closure<?> closure) {
        whenFinalized(Closures.action(closure));
    }

    /**
     * Registers a callback invoked for each materialized root outgoing configuration.
     *
     * @param action variant-level outgoing configuration callback
     */
    void whenOutgoingVariant(Action<? super OutgoingConfigurationSpec> action);

    default void whenOutgoingVariant(Closure<?> closure) {
        whenOutgoingVariant(Closures.action(closure));
    }

    /**
     * Registers a callback invoked for each materialized outgoing slot publication.
     *
     * @param action slot-level outgoing publication callback
     */
    void whenOutgoingSlot(Action<? super OutgoingArtifactSlotSpec> action);

    default void whenOutgoingSlot(Closure<?> closure) {
        whenOutgoingSlot(Closures.action(closure));
    }
}
