// Code generated by qtc from "facets_response.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.

//line app/vlselect/logsql/facets_response.qtpl:1
package logsql

//line app/vlselect/logsql/facets_response.qtpl:1
import (
	"slices"
)

//line app/vlselect/logsql/facets_response.qtpl:7
import (
	qtio422016 "io"

	qt422016 "github.com/valyala/quicktemplate"
)

//line app/vlselect/logsql/facets_response.qtpl:7
var (
	_ = qtio422016.Copy
	_ = qt422016.AcquireByteBuffer
)

//line app/vlselect/logsql/facets_response.qtpl:7
func StreamFacetsResponse(qw422016 *qt422016.Writer, m map[string][]facetEntry) {
//line app/vlselect/logsql/facets_response.qtpl:7
	qw422016.N().S(`{`)
//line app/vlselect/logsql/facets_response.qtpl:10
	sortedKeys := make([]string, 0, len(m))
	for k := range m {
		sortedKeys = append(sortedKeys, k)
	}
	slices.Sort(sortedKeys)

//line app/vlselect/logsql/facets_response.qtpl:15
	qw422016.N().S(`"facets":[`)
//line app/vlselect/logsql/facets_response.qtpl:17
	if len(sortedKeys) > 0 {
//line app/vlselect/logsql/facets_response.qtpl:18
		streamfacetsLine(qw422016, m, sortedKeys[0])
//line app/vlselect/logsql/facets_response.qtpl:19
		for _, k := range sortedKeys[1:] {
//line app/vlselect/logsql/facets_response.qtpl:19
			qw422016.N().S(`,`)
//line app/vlselect/logsql/facets_response.qtpl:20
			streamfacetsLine(qw422016, m, k)
//line app/vlselect/logsql/facets_response.qtpl:21
		}
//line app/vlselect/logsql/facets_response.qtpl:22
	}
//line app/vlselect/logsql/facets_response.qtpl:22
	qw422016.N().S(`]}`)
//line app/vlselect/logsql/facets_response.qtpl:25
}

//line app/vlselect/logsql/facets_response.qtpl:25
func WriteFacetsResponse(qq422016 qtio422016.Writer, m map[string][]facetEntry) {
//line app/vlselect/logsql/facets_response.qtpl:25
	qw422016 := qt422016.AcquireWriter(qq422016)
//line app/vlselect/logsql/facets_response.qtpl:25
	StreamFacetsResponse(qw422016, m)
//line app/vlselect/logsql/facets_response.qtpl:25
	qt422016.ReleaseWriter(qw422016)
//line app/vlselect/logsql/facets_response.qtpl:25
}

//line app/vlselect/logsql/facets_response.qtpl:25
func FacetsResponse(m map[string][]facetEntry) string {
//line app/vlselect/logsql/facets_response.qtpl:25
	qb422016 := qt422016.AcquireByteBuffer()
//line app/vlselect/logsql/facets_response.qtpl:25
	WriteFacetsResponse(qb422016, m)
//line app/vlselect/logsql/facets_response.qtpl:25
	qs422016 := string(qb422016.B)
//line app/vlselect/logsql/facets_response.qtpl:25
	qt422016.ReleaseByteBuffer(qb422016)
//line app/vlselect/logsql/facets_response.qtpl:25
	return qs422016
//line app/vlselect/logsql/facets_response.qtpl:25
}

//line app/vlselect/logsql/facets_response.qtpl:27
func streamfacetsLine(qw422016 *qt422016.Writer, m map[string][]facetEntry, k string) {
//line app/vlselect/logsql/facets_response.qtpl:27
	qw422016.N().S(`{"field_name":`)
//line app/vlselect/logsql/facets_response.qtpl:29
	qw422016.N().Q(k)
//line app/vlselect/logsql/facets_response.qtpl:29
	qw422016.N().S(`,"values":[`)
//line app/vlselect/logsql/facets_response.qtpl:31
	fes := m[k]

//line app/vlselect/logsql/facets_response.qtpl:32
	if len(fes) > 0 {
//line app/vlselect/logsql/facets_response.qtpl:33
		streamfacetLine(qw422016, fes[0])
//line app/vlselect/logsql/facets_response.qtpl:34
		for _, fe := range fes[1:] {
//line app/vlselect/logsql/facets_response.qtpl:34
			qw422016.N().S(`,`)
//line app/vlselect/logsql/facets_response.qtpl:35
			streamfacetLine(qw422016, fe)
//line app/vlselect/logsql/facets_response.qtpl:36
		}
//line app/vlselect/logsql/facets_response.qtpl:37
	}
//line app/vlselect/logsql/facets_response.qtpl:37
	qw422016.N().S(`]}`)
//line app/vlselect/logsql/facets_response.qtpl:40
}

//line app/vlselect/logsql/facets_response.qtpl:40
func writefacetsLine(qq422016 qtio422016.Writer, m map[string][]facetEntry, k string) {
//line app/vlselect/logsql/facets_response.qtpl:40
	qw422016 := qt422016.AcquireWriter(qq422016)
//line app/vlselect/logsql/facets_response.qtpl:40
	streamfacetsLine(qw422016, m, k)
//line app/vlselect/logsql/facets_response.qtpl:40
	qt422016.ReleaseWriter(qw422016)
//line app/vlselect/logsql/facets_response.qtpl:40
}

//line app/vlselect/logsql/facets_response.qtpl:40
func facetsLine(m map[string][]facetEntry, k string) string {
//line app/vlselect/logsql/facets_response.qtpl:40
	qb422016 := qt422016.AcquireByteBuffer()
//line app/vlselect/logsql/facets_response.qtpl:40
	writefacetsLine(qb422016, m, k)
//line app/vlselect/logsql/facets_response.qtpl:40
	qs422016 := string(qb422016.B)
//line app/vlselect/logsql/facets_response.qtpl:40
	qt422016.ReleaseByteBuffer(qb422016)
//line app/vlselect/logsql/facets_response.qtpl:40
	return qs422016
//line app/vlselect/logsql/facets_response.qtpl:40
}

//line app/vlselect/logsql/facets_response.qtpl:42
func streamfacetLine(qw422016 *qt422016.Writer, fe facetEntry) {
//line app/vlselect/logsql/facets_response.qtpl:42
	qw422016.N().S(`{"field_value":`)
//line app/vlselect/logsql/facets_response.qtpl:44
	qw422016.N().Q(fe.value)
//line app/vlselect/logsql/facets_response.qtpl:44
	qw422016.N().S(`,"hits":`)
//line app/vlselect/logsql/facets_response.qtpl:45
	qw422016.N().S(fe.hits)
//line app/vlselect/logsql/facets_response.qtpl:45
	qw422016.N().S(`}`)
//line app/vlselect/logsql/facets_response.qtpl:47
}

//line app/vlselect/logsql/facets_response.qtpl:47
func writefacetLine(qq422016 qtio422016.Writer, fe facetEntry) {
//line app/vlselect/logsql/facets_response.qtpl:47
	qw422016 := qt422016.AcquireWriter(qq422016)
//line app/vlselect/logsql/facets_response.qtpl:47
	streamfacetLine(qw422016, fe)
//line app/vlselect/logsql/facets_response.qtpl:47
	qt422016.ReleaseWriter(qw422016)
//line app/vlselect/logsql/facets_response.qtpl:47
}

//line app/vlselect/logsql/facets_response.qtpl:47
func facetLine(fe facetEntry) string {
//line app/vlselect/logsql/facets_response.qtpl:47
	qb422016 := qt422016.AcquireByteBuffer()
//line app/vlselect/logsql/facets_response.qtpl:47
	writefacetLine(qb422016, fe)
//line app/vlselect/logsql/facets_response.qtpl:47
	qs422016 := string(qb422016.B)
//line app/vlselect/logsql/facets_response.qtpl:47
	qt422016.ReleaseByteBuffer(qb422016)
//line app/vlselect/logsql/facets_response.qtpl:47
	return qs422016
//line app/vlselect/logsql/facets_response.qtpl:47
}
