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

package ozone

// schema: tools.ozone.moderation.emitEvent

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

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

// ModerationEmitEvent_Input is the input argument to a tools.ozone.moderation.emitEvent call.
type ModerationEmitEvent_Input struct {
	CreatedBy       string                             `json:"createdBy" cborgen:"createdBy"`
	Event           *ModerationEmitEvent_Input_Event   `json:"event" cborgen:"event"`
	Subject         *ModerationEmitEvent_Input_Subject `json:"subject" cborgen:"subject"`
	SubjectBlobCids []string                           `json:"subjectBlobCids,omitempty" cborgen:"subjectBlobCids,omitempty"`
}

type ModerationEmitEvent_Input_Event struct {
	ModerationDefs_ModEventTakedown        *ModerationDefs_ModEventTakedown
	ModerationDefs_ModEventAcknowledge     *ModerationDefs_ModEventAcknowledge
	ModerationDefs_ModEventEscalate        *ModerationDefs_ModEventEscalate
	ModerationDefs_ModEventComment         *ModerationDefs_ModEventComment
	ModerationDefs_ModEventLabel           *ModerationDefs_ModEventLabel
	ModerationDefs_ModEventReport          *ModerationDefs_ModEventReport
	ModerationDefs_ModEventMute            *ModerationDefs_ModEventMute
	ModerationDefs_ModEventUnmute          *ModerationDefs_ModEventUnmute
	ModerationDefs_ModEventMuteReporter    *ModerationDefs_ModEventMuteReporter
	ModerationDefs_ModEventUnmuteReporter  *ModerationDefs_ModEventUnmuteReporter
	ModerationDefs_ModEventReverseTakedown *ModerationDefs_ModEventReverseTakedown
	ModerationDefs_ModEventResolveAppeal   *ModerationDefs_ModEventResolveAppeal
	ModerationDefs_ModEventEmail           *ModerationDefs_ModEventEmail
	ModerationDefs_ModEventTag             *ModerationDefs_ModEventTag
}

func (t *ModerationEmitEvent_Input_Event) MarshalJSON() ([]byte, error) {
	if t.ModerationDefs_ModEventTakedown != nil {
		t.ModerationDefs_ModEventTakedown.LexiconTypeID = "tools.ozone.moderation.defs#modEventTakedown"
		return json.Marshal(t.ModerationDefs_ModEventTakedown)
	}
	if t.ModerationDefs_ModEventAcknowledge != nil {
		t.ModerationDefs_ModEventAcknowledge.LexiconTypeID = "tools.ozone.moderation.defs#modEventAcknowledge"
		return json.Marshal(t.ModerationDefs_ModEventAcknowledge)
	}
	if t.ModerationDefs_ModEventEscalate != nil {
		t.ModerationDefs_ModEventEscalate.LexiconTypeID = "tools.ozone.moderation.defs#modEventEscalate"
		return json.Marshal(t.ModerationDefs_ModEventEscalate)
	}
	if t.ModerationDefs_ModEventComment != nil {
		t.ModerationDefs_ModEventComment.LexiconTypeID = "tools.ozone.moderation.defs#modEventComment"
		return json.Marshal(t.ModerationDefs_ModEventComment)
	}
	if t.ModerationDefs_ModEventLabel != nil {
		t.ModerationDefs_ModEventLabel.LexiconTypeID = "tools.ozone.moderation.defs#modEventLabel"
		return json.Marshal(t.ModerationDefs_ModEventLabel)
	}
	if t.ModerationDefs_ModEventReport != nil {
		t.ModerationDefs_ModEventReport.LexiconTypeID = "tools.ozone.moderation.defs#modEventReport"
		return json.Marshal(t.ModerationDefs_ModEventReport)
	}
	if t.ModerationDefs_ModEventMute != nil {
		t.ModerationDefs_ModEventMute.LexiconTypeID = "tools.ozone.moderation.defs#modEventMute"
		return json.Marshal(t.ModerationDefs_ModEventMute)
	}
	if t.ModerationDefs_ModEventUnmute != nil {
		t.ModerationDefs_ModEventUnmute.LexiconTypeID = "tools.ozone.moderation.defs#modEventUnmute"
		return json.Marshal(t.ModerationDefs_ModEventUnmute)
	}
	if t.ModerationDefs_ModEventMuteReporter != nil {
		t.ModerationDefs_ModEventMuteReporter.LexiconTypeID = "tools.ozone.moderation.defs#modEventMuteReporter"
		return json.Marshal(t.ModerationDefs_ModEventMuteReporter)
	}
	if t.ModerationDefs_ModEventUnmuteReporter != nil {
		t.ModerationDefs_ModEventUnmuteReporter.LexiconTypeID = "tools.ozone.moderation.defs#modEventUnmuteReporter"
		return json.Marshal(t.ModerationDefs_ModEventUnmuteReporter)
	}
	if t.ModerationDefs_ModEventReverseTakedown != nil {
		t.ModerationDefs_ModEventReverseTakedown.LexiconTypeID = "tools.ozone.moderation.defs#modEventReverseTakedown"
		return json.Marshal(t.ModerationDefs_ModEventReverseTakedown)
	}
	if t.ModerationDefs_ModEventResolveAppeal != nil {
		t.ModerationDefs_ModEventResolveAppeal.LexiconTypeID = "tools.ozone.moderation.defs#modEventResolveAppeal"
		return json.Marshal(t.ModerationDefs_ModEventResolveAppeal)
	}
	if t.ModerationDefs_ModEventEmail != nil {
		t.ModerationDefs_ModEventEmail.LexiconTypeID = "tools.ozone.moderation.defs#modEventEmail"
		return json.Marshal(t.ModerationDefs_ModEventEmail)
	}
	if t.ModerationDefs_ModEventTag != nil {
		t.ModerationDefs_ModEventTag.LexiconTypeID = "tools.ozone.moderation.defs#modEventTag"
		return json.Marshal(t.ModerationDefs_ModEventTag)
	}
	return nil, fmt.Errorf("cannot marshal empty enum")
}
func (t *ModerationEmitEvent_Input_Event) UnmarshalJSON(b []byte) error {
	typ, err := util.TypeExtract(b)
	if err != nil {
		return err
	}

	switch typ {
	case "tools.ozone.moderation.defs#modEventTakedown":
		t.ModerationDefs_ModEventTakedown = new(ModerationDefs_ModEventTakedown)
		return json.Unmarshal(b, t.ModerationDefs_ModEventTakedown)
	case "tools.ozone.moderation.defs#modEventAcknowledge":
		t.ModerationDefs_ModEventAcknowledge = new(ModerationDefs_ModEventAcknowledge)
		return json.Unmarshal(b, t.ModerationDefs_ModEventAcknowledge)
	case "tools.ozone.moderation.defs#modEventEscalate":
		t.ModerationDefs_ModEventEscalate = new(ModerationDefs_ModEventEscalate)
		return json.Unmarshal(b, t.ModerationDefs_ModEventEscalate)
	case "tools.ozone.moderation.defs#modEventComment":
		t.ModerationDefs_ModEventComment = new(ModerationDefs_ModEventComment)
		return json.Unmarshal(b, t.ModerationDefs_ModEventComment)
	case "tools.ozone.moderation.defs#modEventLabel":
		t.ModerationDefs_ModEventLabel = new(ModerationDefs_ModEventLabel)
		return json.Unmarshal(b, t.ModerationDefs_ModEventLabel)
	case "tools.ozone.moderation.defs#modEventReport":
		t.ModerationDefs_ModEventReport = new(ModerationDefs_ModEventReport)
		return json.Unmarshal(b, t.ModerationDefs_ModEventReport)
	case "tools.ozone.moderation.defs#modEventMute":
		t.ModerationDefs_ModEventMute = new(ModerationDefs_ModEventMute)
		return json.Unmarshal(b, t.ModerationDefs_ModEventMute)
	case "tools.ozone.moderation.defs#modEventUnmute":
		t.ModerationDefs_ModEventUnmute = new(ModerationDefs_ModEventUnmute)
		return json.Unmarshal(b, t.ModerationDefs_ModEventUnmute)
	case "tools.ozone.moderation.defs#modEventMuteReporter":
		t.ModerationDefs_ModEventMuteReporter = new(ModerationDefs_ModEventMuteReporter)
		return json.Unmarshal(b, t.ModerationDefs_ModEventMuteReporter)
	case "tools.ozone.moderation.defs#modEventUnmuteReporter":
		t.ModerationDefs_ModEventUnmuteReporter = new(ModerationDefs_ModEventUnmuteReporter)
		return json.Unmarshal(b, t.ModerationDefs_ModEventUnmuteReporter)
	case "tools.ozone.moderation.defs#modEventReverseTakedown":
		t.ModerationDefs_ModEventReverseTakedown = new(ModerationDefs_ModEventReverseTakedown)
		return json.Unmarshal(b, t.ModerationDefs_ModEventReverseTakedown)
	case "tools.ozone.moderation.defs#modEventResolveAppeal":
		t.ModerationDefs_ModEventResolveAppeal = new(ModerationDefs_ModEventResolveAppeal)
		return json.Unmarshal(b, t.ModerationDefs_ModEventResolveAppeal)
	case "tools.ozone.moderation.defs#modEventEmail":
		t.ModerationDefs_ModEventEmail = new(ModerationDefs_ModEventEmail)
		return json.Unmarshal(b, t.ModerationDefs_ModEventEmail)
	case "tools.ozone.moderation.defs#modEventTag":
		t.ModerationDefs_ModEventTag = new(ModerationDefs_ModEventTag)
		return json.Unmarshal(b, t.ModerationDefs_ModEventTag)

	default:
		return nil
	}
}

type ModerationEmitEvent_Input_Subject struct {
	AdminDefs_RepoRef *comatprototypes.AdminDefs_RepoRef
	RepoStrongRef     *comatprototypes.RepoStrongRef
}

func (t *ModerationEmitEvent_Input_Subject) MarshalJSON() ([]byte, error) {
	if t.AdminDefs_RepoRef != nil {
		t.AdminDefs_RepoRef.LexiconTypeID = "com.atproto.admin.defs#repoRef"
		return json.Marshal(t.AdminDefs_RepoRef)
	}
	if t.RepoStrongRef != nil {
		t.RepoStrongRef.LexiconTypeID = "com.atproto.repo.strongRef"
		return json.Marshal(t.RepoStrongRef)
	}
	return nil, fmt.Errorf("cannot marshal empty enum")
}
func (t *ModerationEmitEvent_Input_Subject) UnmarshalJSON(b []byte) error {
	typ, err := util.TypeExtract(b)
	if err != nil {
		return err
	}

	switch typ {
	case "com.atproto.admin.defs#repoRef":
		t.AdminDefs_RepoRef = new(comatprototypes.AdminDefs_RepoRef)
		return json.Unmarshal(b, t.AdminDefs_RepoRef)
	case "com.atproto.repo.strongRef":
		t.RepoStrongRef = new(comatprototypes.RepoStrongRef)
		return json.Unmarshal(b, t.RepoStrongRef)

	default:
		return nil
	}
}

// ModerationEmitEvent calls the XRPC method "tools.ozone.moderation.emitEvent".
func ModerationEmitEvent(ctx context.Context, c *xrpc.Client, input *ModerationEmitEvent_Input) (*ModerationDefs_ModEventView, error) {
	var out ModerationDefs_ModEventView
	if err := c.Do(ctx, xrpc.Procedure, "application/json", "tools.ozone.moderation.emitEvent", nil, input, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
