package p.studio.lsp.messages;

import java.util.Objects;

public record BaselineDocumentIssue(
        int startLine,
        int startCharacter,
        int endLine,
        int endCharacter,
        BaselineIssueSeverity severity,
        String source,
        String message) {

    public BaselineDocumentIssue {
        severity = Objects.requireNonNull(severity, "severity");
        source = requireText(source, "source");
        message = requireText(message, "message");
    }

    private static String requireText(
            final String value,
            final String field) {
        final String candidate = Objects.requireNonNull(value, field).trim();
        if (candidate.isEmpty()) {
            throw new IllegalArgumentException(field + " must not be blank");
        }
        return candidate;
    }
}
