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

package tangled

// schema: sh.tangled.repo.tree

import (
	"context"

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

const (
	RepoTreeNSID = "sh.tangled.repo.tree"
)

// RepoTree_LastCommit is a "lastCommit" in the sh.tangled.repo.tree schema.
type RepoTree_LastCommit struct {
	Author *RepoTree_Signature `json:"author,omitempty" cborgen:"author,omitempty"`
	// hash: Commit hash
	Hash string `json:"hash" cborgen:"hash"`
	// message: Commit message
	Message string `json:"message" cborgen:"message"`
	// when: Commit timestamp
	When string `json:"when" cborgen:"when"`
}

// RepoTree_Output is the output of a sh.tangled.repo.tree call.
type RepoTree_Output struct {
	// dotdot: Parent directory path
	Dotdot     *string               `json:"dotdot,omitempty" cborgen:"dotdot,omitempty"`
	Files      []*RepoTree_TreeEntry `json:"files" cborgen:"files"`
	LastCommit *RepoTree_LastCommit  `json:"lastCommit,omitempty" cborgen:"lastCommit,omitempty"`
	// parent: The parent path in the tree
	Parent *string `json:"parent,omitempty" cborgen:"parent,omitempty"`
	// readme: Readme for this file tree
	Readme *RepoTree_Readme `json:"readme,omitempty" cborgen:"readme,omitempty"`
	// ref: The git reference used
	Ref string `json:"ref" cborgen:"ref"`
}

// RepoTree_Readme is a "readme" in the sh.tangled.repo.tree schema.
type RepoTree_Readme struct {
	// contents: Contents of the readme file
	Contents string `json:"contents" cborgen:"contents"`
	// filename: Name of the readme file
	Filename string `json:"filename" cborgen:"filename"`
}

// RepoTree_Signature is a "signature" in the sh.tangled.repo.tree schema.
type RepoTree_Signature struct {
	// email: Author email
	Email string `json:"email" cborgen:"email"`
	// name: Author name
	Name string `json:"name" cborgen:"name"`
	// when: Author timestamp
	When string `json:"when" cborgen:"when"`
}

// RepoTree_TreeEntry is a "treeEntry" in the sh.tangled.repo.tree schema.
type RepoTree_TreeEntry struct {
	Last_commit *RepoTree_LastCommit `json:"last_commit,omitempty" cborgen:"last_commit,omitempty"`
	// mode: File mode
	Mode string `json:"mode" cborgen:"mode"`
	// name: Relative file or directory name
	Name string `json:"name" cborgen:"name"`
	// size: File size in bytes
	Size int64 `json:"size" cborgen:"size"`
}

// RepoTree calls the XRPC method "sh.tangled.repo.tree".
//
// path: Path within the repository tree
// ref: Git reference (branch, tag, or commit SHA)
// repo: Repository identifier in format 'did:plc:.../repoName'
func RepoTree(ctx context.Context, c util.LexClient, path string, ref string, repo string) (*RepoTree_Output, error) {
	var out RepoTree_Output

	params := map[string]interface{}{}
	if path != "" {
		params["path"] = path
	}
	params["ref"] = ref
	params["repo"] = repo
	if err := c.LexDo(ctx, util.Query, "", "sh.tangled.repo.tree", params, nil, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
