// 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"
)

// 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"`
	// externalId: An optional external ID for the event, used to deduplicate events from external systems. Fails when an event of same type with the same external ID exists for the same subject.
	ExternalId      *string                            `json:"externalId,omitempty" cborgen:"externalId,omitempty"`
	ModTool         *ModerationDefs_ModTool            `json:"modTool,omitempty" cborgen:"modTool,omitempty"`
	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_ModEventDivert            *ModerationDefs_ModEventDivert
	ModerationDefs_ModEventTag               *ModerationDefs_ModEventTag
	ModerationDefs_AccountEvent              *ModerationDefs_AccountEvent
	ModerationDefs_IdentityEvent             *ModerationDefs_IdentityEvent
	ModerationDefs_RecordEvent               *ModerationDefs_RecordEvent
	ModerationDefs_ModEventPriorityScore     *ModerationDefs_ModEventPriorityScore
	ModerationDefs_AgeAssuranceEvent         *ModerationDefs_AgeAssuranceEvent
	ModerationDefs_AgeAssuranceOverrideEvent *ModerationDefs_AgeAssuranceOverrideEvent
}

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_ModEventDivert != nil {
		t.ModerationDefs_ModEventDivert.LexiconTypeID = "tools.ozone.moderation.defs#modEventDivert"
		return json.Marshal(t.ModerationDefs_ModEventDivert)
	}
	if t.ModerationDefs_ModEventTag != nil {
		t.ModerationDefs_ModEventTag.LexiconTypeID = "tools.ozone.moderation.defs#modEventTag"
		return json.Marshal(t.ModerationDefs_ModEventTag)
	}
	if t.ModerationDefs_AccountEvent != nil {
		t.ModerationDefs_AccountEvent.LexiconTypeID = "tools.ozone.moderation.defs#accountEvent"
		return json.Marshal(t.ModerationDefs_AccountEvent)
	}
	if t.ModerationDefs_IdentityEvent != nil {
		t.ModerationDefs_IdentityEvent.LexiconTypeID = "tools.ozone.moderation.defs#identityEvent"
		return json.Marshal(t.ModerationDefs_IdentityEvent)
	}
	if t.ModerationDefs_RecordEvent != nil {
		t.ModerationDefs_RecordEvent.LexiconTypeID = "tools.ozone.moderation.defs#recordEvent"
		return json.Marshal(t.ModerationDefs_RecordEvent)
	}
	if t.ModerationDefs_ModEventPriorityScore != nil {
		t.ModerationDefs_ModEventPriorityScore.LexiconTypeID = "tools.ozone.moderation.defs#modEventPriorityScore"
		return json.Marshal(t.ModerationDefs_ModEventPriorityScore)
	}
	if t.ModerationDefs_AgeAssuranceEvent != nil {
		t.ModerationDefs_AgeAssuranceEvent.LexiconTypeID = "tools.ozone.moderation.defs#ageAssuranceEvent"
		return json.Marshal(t.ModerationDefs_AgeAssuranceEvent)
	}
	if t.ModerationDefs_AgeAssuranceOverrideEvent != nil {
		t.ModerationDefs_AgeAssuranceOverrideEvent.LexiconTypeID = "tools.ozone.moderation.defs#ageAssuranceOverrideEvent"
		return json.Marshal(t.ModerationDefs_AgeAssuranceOverrideEvent)
	}
	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#modEventDivert":
		t.ModerationDefs_ModEventDivert = new(ModerationDefs_ModEventDivert)
		return json.Unmarshal(b, t.ModerationDefs_ModEventDivert)
	case "tools.ozone.moderation.defs#modEventTag":
		t.ModerationDefs_ModEventTag = new(ModerationDefs_ModEventTag)
		return json.Unmarshal(b, t.ModerationDefs_ModEventTag)
	case "tools.ozone.moderation.defs#accountEvent":
		t.ModerationDefs_AccountEvent = new(ModerationDefs_AccountEvent)
		return json.Unmarshal(b, t.ModerationDefs_AccountEvent)
	case "tools.ozone.moderation.defs#identityEvent":
		t.ModerationDefs_IdentityEvent = new(ModerationDefs_IdentityEvent)
		return json.Unmarshal(b, t.ModerationDefs_IdentityEvent)
	case "tools.ozone.moderation.defs#recordEvent":
		t.ModerationDefs_RecordEvent = new(ModerationDefs_RecordEvent)
		return json.Unmarshal(b, t.ModerationDefs_RecordEvent)
	case "tools.ozone.moderation.defs#modEventPriorityScore":
		t.ModerationDefs_ModEventPriorityScore = new(ModerationDefs_ModEventPriorityScore)
		return json.Unmarshal(b, t.ModerationDefs_ModEventPriorityScore)
	case "tools.ozone.moderation.defs#ageAssuranceEvent":
		t.ModerationDefs_AgeAssuranceEvent = new(ModerationDefs_AgeAssuranceEvent)
		return json.Unmarshal(b, t.ModerationDefs_AgeAssuranceEvent)
	case "tools.ozone.moderation.defs#ageAssuranceOverrideEvent":
		t.ModerationDefs_AgeAssuranceOverrideEvent = new(ModerationDefs_AgeAssuranceOverrideEvent)
		return json.Unmarshal(b, t.ModerationDefs_AgeAssuranceOverrideEvent)

	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 util.LexClient, input *ModerationEmitEvent_Input) (*ModerationDefs_ModEventView, error) {
	var out ModerationDefs_ModEventView
	if err := c.LexDo(ctx, util.Procedure, "application/json", "tools.ozone.moderation.emitEvent", nil, input, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
