// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.

package tangled

// schema: sh.tangled.search.query

import (
	"context"

	"github.com/bluesky-social/indigo/lex/util"
)

const (
	SearchQueryNSID = "sh.tangled.search.query"
)

// SearchQuery_Hit is a "hit" in the sh.tangled.search.query schema.
type SearchQuery_Hit struct {
	Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"`
	// nsid: Collection of the matched record.
	Nsid string `json:"nsid" cborgen:"nsid"`
	// score: Relevance score of the hit, a floating-point number where higher ranks first.
	Score *util.LexiconTypeDecoder `json:"score" cborgen:"score"`
	Uri   string                   `json:"uri" cborgen:"uri"`
	// value: Embedded matched record.
	Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"`
}

// SearchQuery_Output is the output of a sh.tangled.search.query call.
type SearchQuery_Output struct {
	Cursor *string            `json:"cursor,omitempty" cborgen:"cursor,omitempty"`
	Hits   []*SearchQuery_Hit `json:"hits" cborgen:"hits"`
}

// SearchQuery calls the XRPC method "sh.tangled.search.query".
//
// author: Restrict to records authored by this DID.
// cursor: Pagination cursor
// nsid: Restrict to records of this collection.
// q: Full-text search query.
// repo: Restrict to records under this repo DID.
// since: Restrict to records created at or after this time.
// until: Restrict to records created at or before this time.
func SearchQuery(ctx context.Context, c util.LexClient, author string, cursor string, limit int64, nsid string, q string, repo string, since string, until string) (*SearchQuery_Output, error) {
	var out SearchQuery_Output

	params := map[string]interface{}{}
	if author != "" {
		params["author"] = author
	}
	if cursor != "" {
		params["cursor"] = cursor
	}
	if limit != 0 {
		params["limit"] = limit
	}
	if nsid != "" {
		params["nsid"] = nsid
	}
	params["q"] = q
	if repo != "" {
		params["repo"] = repo
	}
	if since != "" {
		params["since"] = since
	}
	if until != "" {
		params["until"] = until
	}
	if err := c.LexDo(ctx, util.Query, "", "sh.tangled.search.query", params, nil, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
