package com.r35157.nenjim.service.journal.model;

import com.r35157.nenjim.service.journal.valuetypes.ArtifactCoordinate;

import java.net.URI;
import java.util.Objects;
import java.util.Optional;

/** Artifact identity and human-facing metadata in one Journal snapshot. */
public record JournalMetadata(
        ArtifactCoordinate coordinate,
        String description,
        Optional<URI> informationUri) {
    public JournalMetadata {
        Objects.requireNonNull(coordinate, "coordinate");
        Objects.requireNonNull(description, "description");
        if (description.isBlank()) {
            throw new IllegalArgumentException("Journal description cannot be blank");
        }
        informationUri = Objects.requireNonNull(informationUri, "informationUri");
        informationUri.ifPresent(uri -> {
            if (!uri.isAbsolute()) {
                throw new IllegalArgumentException("Information URI must be absolute: '" + uri + "'");
            }
        });
    }
}
