package p.packer.models;

import org.apache.commons.lang3.StringUtils;
import p.packer.messages.assets.AssetFamilyCatalog;
import p.packer.messages.assets.OutputCodecCatalog;
import p.packer.messages.assets.OutputFormatCatalog;

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,
        OutputFormatCatalog outputFormat,
        OutputCodecCatalog outputCodec,
        Map<String, String> outputMetadata,
        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");
        outputCodec = Objects.requireNonNull(outputCodec, "outputCodec");
        outputMetadata = Map.copyOf(Objects.requireNonNull(outputMetadata, "outputMetadata"));
        if (StringUtils.isBlank(assetUuid) || StringUtils.isBlank(name)) {
            throw new IllegalArgumentException("declaration fields must not be blank");
        }
    }
}
