package p.studio.workspaces.assets.messages;

import p.packer.messages.AssetReference;
import p.packer.messages.assets.AssetFamilyCatalog;
import p.studio.workspaces.assets.metadata.AssetStudioGlyphSpecialization;

import java.nio.file.Path;
import java.util.Objects;

public record AssetWorkspaceAssetSummary(
        AssetReference assetReference,
        String assetName,
        AssetWorkspaceAssetState state,
        AssetWorkspaceBuildParticipation buildParticipation,
        Integer assetId,
        AssetFamilyCatalog assetFamily,
        AssetStudioGlyphSpecialization glyphSpecialization,
        Path assetRoot,
        boolean preload,
        boolean hasDiagnostics) {

    public AssetWorkspaceAssetSummary {
        Objects.requireNonNull(assetReference, "assetReference");
        assetName = Objects.requireNonNull(assetName, "assetName").trim();
        Objects.requireNonNull(state, "state");
        Objects.requireNonNull(buildParticipation, "buildParticipation");
        assetFamily = Objects.requireNonNullElse(assetFamily, AssetFamilyCatalog.UNKNOWN);
        glyphSpecialization = Objects.requireNonNullElse(glyphSpecialization, AssetStudioGlyphSpecialization.NONE);
        assetRoot = Objects.requireNonNull(assetRoot, "assetRoot").toAbsolutePath().normalize();
        if (assetName.isBlank()) {
            throw new IllegalArgumentException("assetName must not be blank");
        }
        if (state == AssetWorkspaceAssetState.REGISTERED && assetId == null) {
            throw new IllegalArgumentException("registered asset must expose assetId");
        }
        if (state == AssetWorkspaceAssetState.UNREGISTERED && buildParticipation != AssetWorkspaceBuildParticipation.EXCLUDED) {
            throw new IllegalArgumentException("unregistered asset must stay excluded from build participation");
        }
    }
}
