package p.packer.dtos;

import p.packer.messages.assets.AssetFamilyCatalog;
import p.packer.messages.assets.OutputFormatCatalog;

import java.util.Map;
import java.util.Objects;

public record PackerPackSummaryAssetDTO(
        int assetId,
        String assetName,
        AssetFamilyCatalog assetFamily,
        int artifactCount,
        OutputFormatCatalog outputFormat,
        Map<String, String> outputMetadata,
        Map<String, Object> outputPipeline,
        long lastModified) {

    public PackerPackSummaryAssetDTO {
        if (assetId < 0) {
            throw new IllegalArgumentException("assetId must not be negative");
        }
        assetName = Objects.requireNonNull(assetName, "assetName").trim();
        assetFamily = Objects.requireNonNullElse(assetFamily, AssetFamilyCatalog.UNKNOWN);
        outputFormat = Objects.requireNonNullElse(outputFormat, OutputFormatCatalog.UNKNOWN);
        outputMetadata = Map.copyOf(Objects.requireNonNull(outputMetadata, "outputMetadata"));
        outputPipeline = Map.copyOf(Objects.requireNonNull(outputPipeline, "outputPipeline"));
        if (assetName.isBlank()) {
            throw new IllegalArgumentException("assetName must not be blank");
        }
        if (artifactCount < 0) {
            throw new IllegalArgumentException("artifactCount must not be negative");
        }
        if (lastModified < 0L) {
            throw new IllegalArgumentException("lastModified must not be negative");
        }
    }
}
