package graph_queries

import (
	"fmt"

	"visualizador_instanciados/backend_go/queryscope"
)

func hierarchyEdgeQuery(limit int, offset int, includeBNodes bool) string {
	bnodeFilter := ""
	if !includeBNodes {
		bnodeFilter = "FILTER(!isBlank(?s) && !isBlank(?o))"
	}

	pattern := queryscope.NamedGraph(`
{
VALUES ?p { rdfs:subClassOf }
?s ?p ?o .
}
UNION
{
VALUES ?p { rdf:type }
?s ?p ?o .
}
`)

	return fmt.Sprintf(`
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?s ?p ?o
WHERE {
%s
  FILTER(!isLiteral(?o))
  %s
}
ORDER BY ?s ?p ?o
LIMIT %d
OFFSET %d
`, pattern, bnodeFilter, limit, offset)
}

func hierarchyPredicateQuery(includeBNodes bool) string {
	bnodeFilter := ""
	if !includeBNodes {
		bnodeFilter = "FILTER(!isBlank(?s) && !isBlank(?o))"
	}

	pattern := queryscope.NamedGraph(`
{
VALUES ?p { rdfs:subClassOf }
?s ?p ?o .
}
UNION
{
VALUES ?p { rdf:type }
?s ?p ?o .
}
`)

	return fmt.Sprintf(`
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?p
WHERE {
%s
  FILTER(!isLiteral(?o))
  %s
}
ORDER BY ?p
`, pattern, bnodeFilter)
}
