package org.implab.gradle.variants.artifacts;

import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.gradle.api.InvalidUserDataException;

/**
 * Resolves stateful slot assemblies from cheap slot identities.
 *
 * <p>
 * The returned assembly is a materialized build-model handle. It may expose
 * lazy Gradle providers, but
 * it is no longer an identity object suitable for replayable discovery.
 */
@NonNullByDefault
public interface ArtifactAssemblies {
    /**
     * Resolves the assembly for the given slot.
     *
     * <p>
     * This call materializes the build-facing body of the slot from its identity.
     *
     * @param slot slot identity inside a variant outgoing contract
     * @return assembly handle for the slot
     */
    default ArtifactAssembly require(ArtifactSlot slot) {
        return find(slot)
                .orElseThrow(() -> new InvalidUserDataException("Artifact assembly '" + slot + "' isn't registered"));
    }

    Optional<ArtifactAssembly> find(ArtifactSlot slot);
}
