package p.packer.events;

import java.time.Instant;
import java.util.List;
import java.util.Objects;

public record PackerEvent(
        String projectId,
        String operationId,
        long sequence,
        PackerEventKind kind,
        Instant timestamp,
        String summary,
        PackerProgress progress,
        List<String> affectedAssets) {

    public PackerEvent {
        projectId = Objects.requireNonNull(projectId, "projectId").trim();
        operationId = Objects.requireNonNull(operationId, "operationId").trim();
        Objects.requireNonNull(kind, "kind");
        timestamp = Objects.requireNonNull(timestamp, "timestamp");
        summary = Objects.requireNonNull(summary, "summary").trim();
        affectedAssets = List.copyOf(Objects.requireNonNull(affectedAssets, "affectedAssets"));
        if (projectId.isBlank() || operationId.isBlank() || summary.isBlank()) {
            throw new IllegalArgumentException("projectId, operationId, and summary must not be blank");
        }
        if (sequence < 0L) {
            throw new IllegalArgumentException("sequence must not be negative");
        }
    }
}
