package queryscope

import "strings"

// NamedGraph wraps a read pattern so app-generated queries read from any named graph via GRAPH ?g.
func NamedGraph(pattern string) string {
	trimmed := strings.TrimSpace(pattern)
	if trimmed == "" {
		return "  GRAPH ?g {\n  }"
	}

	return indent("GRAPH ?g {\n"+indent(trimmed, "  ")+"\n}", "  ")
}

func AskAnyTripleQuery() string {
	return "ASK WHERE {\n" + NamedGraph("?s ?p ?o .") + "\n}"
}

func indent(text string, prefix string) string {
	lines := strings.Split(text, "\n")
	for i, line := range lines {
		lines[i] = prefix + line
	}
	return strings.Join(lines, "\n")
}
