package p.packer.models;

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

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

public record PackerAssetDeclaration(
        int schemaVersion,
        String assetUuid,
        String name,
        AssetFamilyCatalog assetFamily,
        Map<String, List<String>> inputsByRole,
        String outputFormat,
        OutputCodecCatalog outputCodec,
        boolean preloadEnabled) {

    public PackerAssetDeclaration {
        if (schemaVersion <= 0) {
            throw new IllegalArgumentException("schemaVersion must be positive");
        }
        assetUuid = Objects.requireNonNull(assetUuid, "assetUuid").trim();
        name = Objects.requireNonNull(name, "name").trim();
        assetFamily = Objects.requireNonNull(assetFamily, "assetFamily");
        inputsByRole = Map.copyOf(Objects.requireNonNull(inputsByRole, "inputsByRole"));
        outputFormat = Objects.requireNonNull(outputFormat, "outputFormat").trim();
        outputCodec = Objects.requireNonNull(outputCodec, "outputCodec");
        if (assetUuid.isBlank() || name.isBlank() || outputFormat.isBlank()) {
            throw new IllegalArgumentException("declaration fields must not be blank");
        }
    }
}
