package p.packer.models;

import p.packer.messages.AssetReference;
import p.packer.messages.assets.AssetFamilyCatalog;
import p.packer.messages.assets.PackerAssetState;
import p.packer.messages.assets.PackerBuildParticipation;

import java.util.Objects;

public record PackerAssetSummary(
        AssetReference assetReference,
        PackerAssetIdentity identity,
        PackerAssetState state,
        PackerBuildParticipation buildParticipation,
        AssetFamilyCatalog assetFamily,
        boolean preloadEnabled,
        boolean hasDiagnostics) {

    public PackerAssetSummary {
        Objects.requireNonNull(assetReference, "assetReference");
        Objects.requireNonNull(identity, "identity");
        Objects.requireNonNull(state, "state");
        Objects.requireNonNull(buildParticipation, "buildParticipation");
        assetFamily = Objects.requireNonNullElse(assetFamily, AssetFamilyCatalog.UNKNOWN);
        if (state == PackerAssetState.REGISTERED && identity.assetId() == null) {
            throw new IllegalArgumentException("registered asset must expose assetId");
        }
        if (state == PackerAssetState.UNREGISTERED && buildParticipation != PackerBuildParticipation.EXCLUDED) {
            throw new IllegalArgumentException("unregistered asset must stay excluded from build participation");
        }
    }
}
