package p.studio.lsp.messages;

import java.nio.file.Path;
import java.util.Objects;

public record LspProjectContext(
        String projectKey,
        String languageId,
        Path projectRoot) {

    public LspProjectContext {
        projectKey = requireText(projectKey, "projectKey");
        languageId = requireText(languageId, "languageId");
        projectRoot = Objects.requireNonNull(projectRoot, "projectRoot").toAbsolutePath().normalize();
    }

    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;
    }
}
