package p.studio.lsp.events;

import p.packer.events.PackerEventKind;

import java.util.Objects;

public record StudioPackerOperationEvent(
        String operationId,
        PackerEventKind kind,
        String summary,
        Double progress,
        boolean indeterminate) implements StudioEvent {

    public StudioPackerOperationEvent {
        operationId = Objects.requireNonNull(operationId, "operationId").trim();
        Objects.requireNonNull(kind, "kind");
        summary = Objects.requireNonNull(summary, "summary").trim();
        if (operationId.isBlank() || summary.isBlank()) {
            throw new IllegalArgumentException("operationId and summary must not be blank");
        }
        if (progress != null && !indeterminate && (progress < 0.0d || progress > 1.0d)) {
            throw new IllegalArgumentException("progress must be between 0.0 and 1.0 when determinate");
        }
    }
}
