package p.packer.messages;

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

import java.util.Objects;

public record CreateAssetRequest(
        PackerProjectContext project,
        String assetRoot,
        String assetName,
        AssetFamilyCatalog assetFamily,
        OutputFormatCatalog outputFormat,
        OutputCodecCatalog outputCodec,
        boolean preloadEnabled) {

    public CreateAssetRequest {
        Objects.requireNonNull(project, "project");
        assetRoot = Objects.requireNonNull(assetRoot, "assetRoot").trim();
        assetName = Objects.requireNonNull(assetName, "assetName").trim();
        assetFamily = Objects.requireNonNullElse(assetFamily, AssetFamilyCatalog.UNKNOWN);
        outputFormat = Objects.requireNonNullElse(outputFormat, OutputFormatCatalog.UNKNOWN);
        outputCodec = Objects.requireNonNullElse(outputCodec, OutputCodecCatalog.UNKNOWN);
        if (assetRoot.isBlank()) {
            throw new IllegalArgumentException("assetRoot must not be blank");
        }
        if (assetName.isBlank()) {
            throw new IllegalArgumentException("assetName must not be blank");
        }
    }
}
