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

package tangled

// schema: sh.tangled.repo.listPulls

import (
	"context"

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

const (
	RepoListPullsNSID = "sh.tangled.repo.listPulls"
)

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

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

// RepoListPulls calls the XRPC method "sh.tangled.repo.listPulls".
//
// author: Restrict to pulls authored by this user DID.
// cursor: Pagination cursor
// order: Sort direction by createdAt.
// status: Restrict to pulls whose latest derived status matches.
// subject: Repo DID to list pulls for
func RepoListPulls(ctx context.Context, c util.LexClient, author string, cursor string, limit int64, order string, status string, subject string) (*RepoListPulls_Output, error) {
	var out RepoListPulls_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 status != "" {
		params["status"] = status
	}
	params["subject"] = subject
	if err := c.LexDo(ctx, util.Query, "", "sh.tangled.repo.listPulls", params, nil, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
