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

package org_tangled

// schema: org.tangled.repo.listIssues

import (
	"context"

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

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

// RepoListIssues_IssueListItem is a "issueListItem" in the org.tangled.repo.listIssues schema.
type RepoListIssues_IssueListItem struct {
	// author: The account that opened the record, the editor of its first version. Left out when the author can't be told.
	Author *string `json:"author,omitempty" cborgen:"author,omitempty"`
	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 org.tangled.repo.listIssues call.
type RepoListIssues_Output struct {
	Cursor *string                         `json:"cursor,omitempty" cborgen:"cursor,omitempty"`
	Items  []*RepoListIssues_IssueListItem `json:"items" cborgen:"items"`
	// total: Total items in the full list; omitted for filtered or merged views
	Total *int64 `json:"total,omitempty" cborgen:"total,omitempty"`
}

// RepoListIssues calls the XRPC method "org.tangled.repo.listIssues".
//
// author: Restrict to issues authored by this user DID.
// cursor: Pagination cursor
// offset: Absolute offset for random-access pagination. Mutually exclusive with cursor; offsets drift under concurrent writes, so follow up with the returned 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, offset 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 offset != 0 {
		params["offset"] = offset
	}
	if order != "" {
		params["order"] = order
	}
	if state != "" {
		params["state"] = state
	}
	params["subject"] = subject
	if err := c.LexDo(ctx, util.Query, "", "org.tangled.repo.listIssues", params, nil, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
