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

package ozone

// schema: tools.ozone.hosting.getAccountHistory

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

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

// HostingGetAccountHistory_AccountCreated is a "accountCreated" in the tools.ozone.hosting.getAccountHistory schema.
//
// RECORDTYPE: HostingGetAccountHistory_AccountCreated
type HostingGetAccountHistory_AccountCreated struct {
	LexiconTypeID string  `json:"$type,const=tools.ozone.hosting.getAccountHistory#accountCreated" cborgen:"$type,const=tools.ozone.hosting.getAccountHistory#accountCreated"`
	Email         *string `json:"email,omitempty" cborgen:"email,omitempty"`
	Handle        *string `json:"handle,omitempty" cborgen:"handle,omitempty"`
}

// HostingGetAccountHistory_EmailConfirmed is a "emailConfirmed" in the tools.ozone.hosting.getAccountHistory schema.
//
// RECORDTYPE: HostingGetAccountHistory_EmailConfirmed
type HostingGetAccountHistory_EmailConfirmed struct {
	LexiconTypeID string `json:"$type,const=tools.ozone.hosting.getAccountHistory#emailConfirmed" cborgen:"$type,const=tools.ozone.hosting.getAccountHistory#emailConfirmed"`
	Email         string `json:"email" cborgen:"email"`
}

// HostingGetAccountHistory_EmailUpdated is a "emailUpdated" in the tools.ozone.hosting.getAccountHistory schema.
//
// RECORDTYPE: HostingGetAccountHistory_EmailUpdated
type HostingGetAccountHistory_EmailUpdated struct {
	LexiconTypeID string `json:"$type,const=tools.ozone.hosting.getAccountHistory#emailUpdated" cborgen:"$type,const=tools.ozone.hosting.getAccountHistory#emailUpdated"`
	Email         string `json:"email" cborgen:"email"`
}

// HostingGetAccountHistory_Event is a "event" in the tools.ozone.hosting.getAccountHistory schema.
type HostingGetAccountHistory_Event struct {
	CreatedAt string                                  `json:"createdAt" cborgen:"createdAt"`
	CreatedBy string                                  `json:"createdBy" cborgen:"createdBy"`
	Details   *HostingGetAccountHistory_Event_Details `json:"details" cborgen:"details"`
}

type HostingGetAccountHistory_Event_Details struct {
	HostingGetAccountHistory_AccountCreated  *HostingGetAccountHistory_AccountCreated
	HostingGetAccountHistory_EmailUpdated    *HostingGetAccountHistory_EmailUpdated
	HostingGetAccountHistory_EmailConfirmed  *HostingGetAccountHistory_EmailConfirmed
	HostingGetAccountHistory_PasswordUpdated *HostingGetAccountHistory_PasswordUpdated
	HostingGetAccountHistory_HandleUpdated   *HostingGetAccountHistory_HandleUpdated
}

func (t *HostingGetAccountHistory_Event_Details) MarshalJSON() ([]byte, error) {
	if t.HostingGetAccountHistory_AccountCreated != nil {
		t.HostingGetAccountHistory_AccountCreated.LexiconTypeID = "tools.ozone.hosting.getAccountHistory#accountCreated"
		return json.Marshal(t.HostingGetAccountHistory_AccountCreated)
	}
	if t.HostingGetAccountHistory_EmailUpdated != nil {
		t.HostingGetAccountHistory_EmailUpdated.LexiconTypeID = "tools.ozone.hosting.getAccountHistory#emailUpdated"
		return json.Marshal(t.HostingGetAccountHistory_EmailUpdated)
	}
	if t.HostingGetAccountHistory_EmailConfirmed != nil {
		t.HostingGetAccountHistory_EmailConfirmed.LexiconTypeID = "tools.ozone.hosting.getAccountHistory#emailConfirmed"
		return json.Marshal(t.HostingGetAccountHistory_EmailConfirmed)
	}
	if t.HostingGetAccountHistory_PasswordUpdated != nil {
		t.HostingGetAccountHistory_PasswordUpdated.LexiconTypeID = "tools.ozone.hosting.getAccountHistory#passwordUpdated"
		return json.Marshal(t.HostingGetAccountHistory_PasswordUpdated)
	}
	if t.HostingGetAccountHistory_HandleUpdated != nil {
		t.HostingGetAccountHistory_HandleUpdated.LexiconTypeID = "tools.ozone.hosting.getAccountHistory#handleUpdated"
		return json.Marshal(t.HostingGetAccountHistory_HandleUpdated)
	}
	return nil, fmt.Errorf("cannot marshal empty enum")
}
func (t *HostingGetAccountHistory_Event_Details) UnmarshalJSON(b []byte) error {
	typ, err := util.TypeExtract(b)
	if err != nil {
		return err
	}

	switch typ {
	case "tools.ozone.hosting.getAccountHistory#accountCreated":
		t.HostingGetAccountHistory_AccountCreated = new(HostingGetAccountHistory_AccountCreated)
		return json.Unmarshal(b, t.HostingGetAccountHistory_AccountCreated)
	case "tools.ozone.hosting.getAccountHistory#emailUpdated":
		t.HostingGetAccountHistory_EmailUpdated = new(HostingGetAccountHistory_EmailUpdated)
		return json.Unmarshal(b, t.HostingGetAccountHistory_EmailUpdated)
	case "tools.ozone.hosting.getAccountHistory#emailConfirmed":
		t.HostingGetAccountHistory_EmailConfirmed = new(HostingGetAccountHistory_EmailConfirmed)
		return json.Unmarshal(b, t.HostingGetAccountHistory_EmailConfirmed)
	case "tools.ozone.hosting.getAccountHistory#passwordUpdated":
		t.HostingGetAccountHistory_PasswordUpdated = new(HostingGetAccountHistory_PasswordUpdated)
		return json.Unmarshal(b, t.HostingGetAccountHistory_PasswordUpdated)
	case "tools.ozone.hosting.getAccountHistory#handleUpdated":
		t.HostingGetAccountHistory_HandleUpdated = new(HostingGetAccountHistory_HandleUpdated)
		return json.Unmarshal(b, t.HostingGetAccountHistory_HandleUpdated)

	default:
		return nil
	}
}

// HostingGetAccountHistory_HandleUpdated is a "handleUpdated" in the tools.ozone.hosting.getAccountHistory schema.
//
// RECORDTYPE: HostingGetAccountHistory_HandleUpdated
type HostingGetAccountHistory_HandleUpdated struct {
	LexiconTypeID string `json:"$type,const=tools.ozone.hosting.getAccountHistory#handleUpdated" cborgen:"$type,const=tools.ozone.hosting.getAccountHistory#handleUpdated"`
	Handle        string `json:"handle" cborgen:"handle"`
}

// HostingGetAccountHistory_Output is the output of a tools.ozone.hosting.getAccountHistory call.
type HostingGetAccountHistory_Output struct {
	Cursor *string                           `json:"cursor,omitempty" cborgen:"cursor,omitempty"`
	Events []*HostingGetAccountHistory_Event `json:"events" cborgen:"events"`
}

// HostingGetAccountHistory_PasswordUpdated is a "passwordUpdated" in the tools.ozone.hosting.getAccountHistory schema.
//
// RECORDTYPE: HostingGetAccountHistory_PasswordUpdated
type HostingGetAccountHistory_PasswordUpdated struct {
	LexiconTypeID string `json:"$type,const=tools.ozone.hosting.getAccountHistory#passwordUpdated" cborgen:"$type,const=tools.ozone.hosting.getAccountHistory#passwordUpdated"`
}

// HostingGetAccountHistory calls the XRPC method "tools.ozone.hosting.getAccountHistory".
func HostingGetAccountHistory(ctx context.Context, c util.LexClient, cursor string, did string, events []string, limit int64) (*HostingGetAccountHistory_Output, error) {
	var out HostingGetAccountHistory_Output

	params := map[string]interface{}{}
	if cursor != "" {
		params["cursor"] = cursor
	}
	params["did"] = did
	if len(events) != 0 {
		params["events"] = events
	}
	if limit != 0 {
		params["limit"] = limit
	}
	if err := c.LexDo(ctx, util.Query, "", "tools.ozone.hosting.getAccountHistory", params, nil, &out); err != nil {
		return nil, err
	}

	return &out, nil
}
