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

package tangled

// schema: sh.tangled.repo.listIssues

import (
	"context"

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

const (
	RepoListIssuesNSID = "sh.tangled.repo.listIssues"
)

// RepoListIssues_IssueListItem is a "issueListItem" in the sh.tangled.repo.listIssues schema.
type RepoListIssues_IssueListItem struct {
	Cid *string `json:"cid,omitempty" cborgen:"cid,omitempty"`
	// commentCount: Count of sh.tangled.repo.issue.comment records targeting this issue.
	CommentCount int64 `json:"commentCount" cborgen:"commentCount"`
	// state: Latest derived state.
	State string `json:"state" cborgen:"state"`
	// stateUpdatedAt: TID-derived timestamp of the latest state record.
	StateUpdatedAt *string `json:"stateUpdatedAt,omitempty" cborgen:"stateUpdatedAt,omitempty"`
	Uri            string  `json:"uri" cborgen:"uri"`
	// value: Embedded sh.tangled.repo.issue record
	Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"`
}

// RepoListIssues_Output is the output of a sh.tangled.repo.listIssues call.
type RepoListIssues_Output struct {
	Cursor *string                         `json:"cursor,omitempty" cborgen:"cursor,omitempty"`
	Items  []*RepoListIssues_IssueListItem `json:"items" cborgen:"items"`
}

// RepoListIssues calls the XRPC method "sh.tangled.repo.listIssues".
//
// author: Restrict to issues authored by this user DID.
// cursor: Pagination cursor
// order: Sort direction by createdAt.
// state: Restrict to issues whose latest derived state matches.
// subject: Repo DID to list issues for
func RepoListIssues(ctx context.Context, c util.LexClient, author string, cursor string, limit int64, order string, state string, subject string) (*RepoListIssues_Output, error) {
	var out RepoListIssues_Output

	params := map[string]interface{}{}
	if author != "" {
		params["author"] = author
	}
	if cursor != "" {
		params["cursor"] = cursor
	}
	if limit != 0 {
		params["limit"] = limit
	}
	if order != "" {
		params["order"] = order
	}
	if state != "" {
		params["state"] = state
	}
	params["subject"] = subject
	if err := c.LexDo(ctx, util.Query, "", "sh.tangled.repo.listIssues", params, nil, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
