package p.studio.workspaces.assets.messages;

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

public record AssetWorkspaceBankCompositionFile(
        String path,
        String displayName,
        long size,
        long lastModified,
        String fingerprint,
        Map<String, Object> metadata) {

    public AssetWorkspaceBankCompositionFile {
        path = Objects.requireNonNull(path, "path").trim();
        displayName = Objects.requireNonNull(displayName, "displayName").trim();
        if (path.isBlank()) {
            throw new IllegalArgumentException("path must not be blank");
        }
        if (displayName.isBlank()) {
            throw new IllegalArgumentException("displayName must not be blank");
        }
        if (size < 0L) {
            throw new IllegalArgumentException("size must be non-negative");
        }
        if (lastModified < 0L) {
            throw new IllegalArgumentException("lastModified must be non-negative");
        }
        fingerprint = fingerprint == null || fingerprint.isBlank() ? null : fingerprint;
        metadata = Map.copyOf(new LinkedHashMap<>(Objects.requireNonNull(metadata, "metadata")));
    }
}
