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

package tangled

// schema: org.tangled.temp.search.searchCode

import (
	"context"

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

const (
	TempSearchSearchCodeNSID = "org.tangled.temp.search.searchCode"
)

// TempSearchSearchCode_Chunk is a "chunk" in the org.tangled.temp.search.searchCode schema.
type TempSearchSearchCode_Chunk struct {
	// content: Source lines for this match chunk.
	Content string `json:"content" cborgen:"content"`
	// highlights: Byte-offset ranges within content that match the query.
	Highlights []*TempSearchSearchCode_Highlight `json:"highlights,omitempty" cborgen:"highlights,omitempty"`
	// lineStart: 1-based line number of the first line in content.
	LineStart int64 `json:"lineStart" cborgen:"lineStart"`
}

// TempSearchSearchCode_FileResult is a "fileResult" in the org.tangled.temp.search.searchCode schema.
type TempSearchSearchCode_FileResult struct {
	Chunks []*TempSearchSearchCode_Chunk `json:"chunks" cborgen:"chunks"`
	// language: Detected programming language.
	Language *string `json:"language,omitempty" cborgen:"language,omitempty"`
	// path: File path relative to repository root.
	Path string `json:"path" cborgen:"path"`
	// repoDid: DID of the repository as minted by the knot.
	RepoDid string `json:"repoDid" cborgen:"repoDid"`
}

// TempSearchSearchCode_Highlight is a "highlight" in the org.tangled.temp.search.searchCode schema.
type TempSearchSearchCode_Highlight struct {
	// end: End byte offset (exclusive) within the chunk content string.
	End int64 `json:"end" cborgen:"end"`
	// start: Start byte offset within the chunk content string.
	Start int64 `json:"start" cborgen:"start"`
}

// TempSearchSearchCode_Output is the output of a org.tangled.temp.search.searchCode call.
type TempSearchSearchCode_Output struct {
	Cursor  *string                            `json:"cursor,omitempty" cborgen:"cursor,omitempty"`
	Results []*TempSearchSearchCode_FileResult `json:"results" cborgen:"results"`
}

// TempSearchSearchCode calls the XRPC method "org.tangled.temp.search.searchCode".
//
// lang: Restrict search to a specific programming language (e.g. 'go', 'rust').
// q: Search query string.
// repoDid: Restrict search to a specific repository, by its DID.
func TempSearchSearchCode(ctx context.Context, c util.LexClient, cursor string, lang string, limit int64, q string, repoDid string) (*TempSearchSearchCode_Output, error) {
	var out TempSearchSearchCode_Output

	params := map[string]interface{}{}
	if cursor != "" {
		params["cursor"] = cursor
	}
	if lang != "" {
		params["lang"] = lang
	}
	if limit != 0 {
		params["limit"] = limit
	}
	params["q"] = q
	if repoDid != "" {
		params["repoDid"] = repoDid
	}
	if err := c.LexDo(ctx, util.Query, "", "org.tangled.temp.search.searchCode", params, nil, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
