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

package chat

// schema: chat.bsky.convo.getLog

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

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

// ConvoGetLog_Output is the output of a chat.bsky.convo.getLog call.
type ConvoGetLog_Output struct {
	Cursor *string                         `json:"cursor,omitempty" cborgen:"cursor,omitempty"`
	Logs   []*ConvoGetLog_Output_Logs_Elem `json:"logs" cborgen:"logs"`
}

type ConvoGetLog_Output_Logs_Elem struct {
	ConvoDefs_LogBeginConvo    *ConvoDefs_LogBeginConvo
	ConvoDefs_LogLeaveConvo    *ConvoDefs_LogLeaveConvo
	ConvoDefs_LogCreateMessage *ConvoDefs_LogCreateMessage
	ConvoDefs_LogDeleteMessage *ConvoDefs_LogDeleteMessage
}

func (t *ConvoGetLog_Output_Logs_Elem) MarshalJSON() ([]byte, error) {
	if t.ConvoDefs_LogBeginConvo != nil {
		t.ConvoDefs_LogBeginConvo.LexiconTypeID = "chat.bsky.convo.defs#logBeginConvo"
		return json.Marshal(t.ConvoDefs_LogBeginConvo)
	}
	if t.ConvoDefs_LogLeaveConvo != nil {
		t.ConvoDefs_LogLeaveConvo.LexiconTypeID = "chat.bsky.convo.defs#logLeaveConvo"
		return json.Marshal(t.ConvoDefs_LogLeaveConvo)
	}
	if t.ConvoDefs_LogCreateMessage != nil {
		t.ConvoDefs_LogCreateMessage.LexiconTypeID = "chat.bsky.convo.defs#logCreateMessage"
		return json.Marshal(t.ConvoDefs_LogCreateMessage)
	}
	if t.ConvoDefs_LogDeleteMessage != nil {
		t.ConvoDefs_LogDeleteMessage.LexiconTypeID = "chat.bsky.convo.defs#logDeleteMessage"
		return json.Marshal(t.ConvoDefs_LogDeleteMessage)
	}
	return nil, fmt.Errorf("cannot marshal empty enum")
}
func (t *ConvoGetLog_Output_Logs_Elem) UnmarshalJSON(b []byte) error {
	typ, err := util.TypeExtract(b)
	if err != nil {
		return err
	}

	switch typ {
	case "chat.bsky.convo.defs#logBeginConvo":
		t.ConvoDefs_LogBeginConvo = new(ConvoDefs_LogBeginConvo)
		return json.Unmarshal(b, t.ConvoDefs_LogBeginConvo)
	case "chat.bsky.convo.defs#logLeaveConvo":
		t.ConvoDefs_LogLeaveConvo = new(ConvoDefs_LogLeaveConvo)
		return json.Unmarshal(b, t.ConvoDefs_LogLeaveConvo)
	case "chat.bsky.convo.defs#logCreateMessage":
		t.ConvoDefs_LogCreateMessage = new(ConvoDefs_LogCreateMessage)
		return json.Unmarshal(b, t.ConvoDefs_LogCreateMessage)
	case "chat.bsky.convo.defs#logDeleteMessage":
		t.ConvoDefs_LogDeleteMessage = new(ConvoDefs_LogDeleteMessage)
		return json.Unmarshal(b, t.ConvoDefs_LogDeleteMessage)

	default:
		return nil
	}
}

// ConvoGetLog calls the XRPC method "chat.bsky.convo.getLog".
func ConvoGetLog(ctx context.Context, c *xrpc.Client, cursor string) (*ConvoGetLog_Output, error) {
	var out ConvoGetLog_Output

	params := map[string]interface{}{
		"cursor": cursor,
	}
	if err := c.Do(ctx, xrpc.Query, "", "chat.bsky.convo.getLog", params, nil, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
