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

package tangled

// schema: sh.tangled.git.keepCommit

import (
	"context"
	"encoding/json"
	"fmt"

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

const (
	GitKeepCommitNSID = "sh.tangled.git.keepCommit"
)

// GitKeepCommit_Commit is a "commit" in the sh.tangled.git.keepCommit schema.
//
// RECORDTYPE: GitKeepCommit_Commit
type GitKeepCommit_Commit struct {
	LexiconTypeID string `json:"$type,const=sh.tangled.git.keepCommit#commit" cborgen:"$type,const=sh.tangled.git.keepCommit#commit"`
	Oid           string `json:"oid" cborgen:"oid"`
	Repo          string `json:"repo" cborgen:"repo"`
}

// GitKeepCommit_Input is the input argument to a sh.tangled.git.keepCommit call.
type GitKeepCommit_Input struct {
	// record: at-uri of target record. rkey is required
	Record string                      `json:"record" cborgen:"record"`
	Repo   string                      `json:"repo" cborgen:"repo"`
	Source *GitKeepCommit_Input_Source `json:"source" cborgen:"source"`
}

type GitKeepCommit_Input_Source struct {
	GitKeepCommit_Commit  *GitKeepCommit_Commit
	GitKeepCommit_Patches *GitKeepCommit_Patches
}

func (t *GitKeepCommit_Input_Source) MarshalJSON() ([]byte, error) {
	if t.GitKeepCommit_Commit != nil {
		t.GitKeepCommit_Commit.LexiconTypeID = "sh.tangled.git.keepCommit#commit"
		return json.Marshal(t.GitKeepCommit_Commit)
	}
	if t.GitKeepCommit_Patches != nil {
		t.GitKeepCommit_Patches.LexiconTypeID = "sh.tangled.git.keepCommit#patches"
		return json.Marshal(t.GitKeepCommit_Patches)
	}
	return nil, fmt.Errorf("cannot marshal empty enum")
}
func (t *GitKeepCommit_Input_Source) UnmarshalJSON(b []byte) error {
	typ, err := util.TypeExtract(b)
	if err != nil {
		return err
	}

	switch typ {
	case "sh.tangled.git.keepCommit#commit":
		t.GitKeepCommit_Commit = new(GitKeepCommit_Commit)
		return json.Unmarshal(b, t.GitKeepCommit_Commit)
	case "sh.tangled.git.keepCommit#patches":
		t.GitKeepCommit_Patches = new(GitKeepCommit_Patches)
		return json.Unmarshal(b, t.GitKeepCommit_Patches)

	default:
		return nil
	}
}

// GitKeepCommit_Output is the output of a sh.tangled.git.keepCommit call.
type GitKeepCommit_Output struct {
	Commit string `json:"commit" cborgen:"commit"`
}

// GitKeepCommit_Patches is a "patches" in the sh.tangled.git.keepCommit schema.
//
// RECORDTYPE: GitKeepCommit_Patches
type GitKeepCommit_Patches struct {
	LexiconTypeID string   `json:"$type,const=sh.tangled.git.keepCommit#patches" cborgen:"$type,const=sh.tangled.git.keepCommit#patches"`
	Patches       []string `json:"patches,omitempty" cborgen:"patches,omitempty"`
}

// GitKeepCommit calls the XRPC method "sh.tangled.git.keepCommit".
func GitKeepCommit(ctx context.Context, c util.LexClient, input *GitKeepCommit_Input) (*GitKeepCommit_Output, error) {
	var out GitKeepCommit_Output
	if err := c.LexDo(ctx, util.Procedure, "application/json", "sh.tangled.git.keepCommit", nil, input, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
