// Code generated by gotdgen, DO NOT EDIT.

package tdapi

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

// No-op definition for keeping imports.
var (
	_ = bin.Buffer{}
	_ = context.Background()
	_ = fmt.Stringer(nil)
	_ = strings.Builder{}
	_ = errors.Is
	_ = multierr.AppendInto
	_ = sort.Ints
	_ = tdp.Format
	_ = tgerr.Error{}
	_ = tdjson.Encoder{}
)

// ReactionUnavailabilityReasonAnonymousAdministrator represents TL type `reactionUnavailabilityReasonAnonymousAdministrator#e23883fb`.
type ReactionUnavailabilityReasonAnonymousAdministrator struct {
}

// ReactionUnavailabilityReasonAnonymousAdministratorTypeID is TL type id of ReactionUnavailabilityReasonAnonymousAdministrator.
const ReactionUnavailabilityReasonAnonymousAdministratorTypeID = 0xe23883fb

// construct implements constructor of ReactionUnavailabilityReasonClass.
func (r ReactionUnavailabilityReasonAnonymousAdministrator) construct() ReactionUnavailabilityReasonClass {
	return &r
}

// Ensuring interfaces in compile-time for ReactionUnavailabilityReasonAnonymousAdministrator.
var (
	_ bin.Encoder     = &ReactionUnavailabilityReasonAnonymousAdministrator{}
	_ bin.Decoder     = &ReactionUnavailabilityReasonAnonymousAdministrator{}
	_ bin.BareEncoder = &ReactionUnavailabilityReasonAnonymousAdministrator{}
	_ bin.BareDecoder = &ReactionUnavailabilityReasonAnonymousAdministrator{}

	_ ReactionUnavailabilityReasonClass = &ReactionUnavailabilityReasonAnonymousAdministrator{}
)

func (r *ReactionUnavailabilityReasonAnonymousAdministrator) Zero() bool {
	if r == nil {
		return true
	}

	return true
}

// String implements fmt.Stringer.
func (r *ReactionUnavailabilityReasonAnonymousAdministrator) String() string {
	if r == nil {
		return "ReactionUnavailabilityReasonAnonymousAdministrator(nil)"
	}
	type Alias ReactionUnavailabilityReasonAnonymousAdministrator
	return fmt.Sprintf("ReactionUnavailabilityReasonAnonymousAdministrator%+v", Alias(*r))
}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*ReactionUnavailabilityReasonAnonymousAdministrator) TypeID() uint32 {
	return ReactionUnavailabilityReasonAnonymousAdministratorTypeID
}

// TypeName returns name of type in TL schema.
func (*ReactionUnavailabilityReasonAnonymousAdministrator) TypeName() string {
	return "reactionUnavailabilityReasonAnonymousAdministrator"
}

// TypeInfo returns info about TL type.
func (r *ReactionUnavailabilityReasonAnonymousAdministrator) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "reactionUnavailabilityReasonAnonymousAdministrator",
		ID:   ReactionUnavailabilityReasonAnonymousAdministratorTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (r *ReactionUnavailabilityReasonAnonymousAdministrator) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reactionUnavailabilityReasonAnonymousAdministrator#e23883fb as nil")
	}
	b.PutID(ReactionUnavailabilityReasonAnonymousAdministratorTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ReactionUnavailabilityReasonAnonymousAdministrator) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reactionUnavailabilityReasonAnonymousAdministrator#e23883fb as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (r *ReactionUnavailabilityReasonAnonymousAdministrator) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode reactionUnavailabilityReasonAnonymousAdministrator#e23883fb to nil")
	}
	if err := b.ConsumeID(ReactionUnavailabilityReasonAnonymousAdministratorTypeID); err != nil {
		return fmt.Errorf("unable to decode reactionUnavailabilityReasonAnonymousAdministrator#e23883fb: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *ReactionUnavailabilityReasonAnonymousAdministrator) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode reactionUnavailabilityReasonAnonymousAdministrator#e23883fb to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *ReactionUnavailabilityReasonAnonymousAdministrator) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode reactionUnavailabilityReasonAnonymousAdministrator#e23883fb as nil")
	}
	b.ObjStart()
	b.PutID("reactionUnavailabilityReasonAnonymousAdministrator")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *ReactionUnavailabilityReasonAnonymousAdministrator) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode reactionUnavailabilityReasonAnonymousAdministrator#e23883fb to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("reactionUnavailabilityReasonAnonymousAdministrator"); err != nil {
				return fmt.Errorf("unable to decode reactionUnavailabilityReasonAnonymousAdministrator#e23883fb: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// ReactionUnavailabilityReasonGuest represents TL type `reactionUnavailabilityReasonGuest#50ef5244`.
type ReactionUnavailabilityReasonGuest struct {
}

// ReactionUnavailabilityReasonGuestTypeID is TL type id of ReactionUnavailabilityReasonGuest.
const ReactionUnavailabilityReasonGuestTypeID = 0x50ef5244

// construct implements constructor of ReactionUnavailabilityReasonClass.
func (r ReactionUnavailabilityReasonGuest) construct() ReactionUnavailabilityReasonClass { return &r }

// Ensuring interfaces in compile-time for ReactionUnavailabilityReasonGuest.
var (
	_ bin.Encoder     = &ReactionUnavailabilityReasonGuest{}
	_ bin.Decoder     = &ReactionUnavailabilityReasonGuest{}
	_ bin.BareEncoder = &ReactionUnavailabilityReasonGuest{}
	_ bin.BareDecoder = &ReactionUnavailabilityReasonGuest{}

	_ ReactionUnavailabilityReasonClass = &ReactionUnavailabilityReasonGuest{}
)

func (r *ReactionUnavailabilityReasonGuest) Zero() bool {
	if r == nil {
		return true
	}

	return true
}

// String implements fmt.Stringer.
func (r *ReactionUnavailabilityReasonGuest) String() string {
	if r == nil {
		return "ReactionUnavailabilityReasonGuest(nil)"
	}
	type Alias ReactionUnavailabilityReasonGuest
	return fmt.Sprintf("ReactionUnavailabilityReasonGuest%+v", Alias(*r))
}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*ReactionUnavailabilityReasonGuest) TypeID() uint32 {
	return ReactionUnavailabilityReasonGuestTypeID
}

// TypeName returns name of type in TL schema.
func (*ReactionUnavailabilityReasonGuest) TypeName() string {
	return "reactionUnavailabilityReasonGuest"
}

// TypeInfo returns info about TL type.
func (r *ReactionUnavailabilityReasonGuest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "reactionUnavailabilityReasonGuest",
		ID:   ReactionUnavailabilityReasonGuestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (r *ReactionUnavailabilityReasonGuest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reactionUnavailabilityReasonGuest#50ef5244 as nil")
	}
	b.PutID(ReactionUnavailabilityReasonGuestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ReactionUnavailabilityReasonGuest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode reactionUnavailabilityReasonGuest#50ef5244 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (r *ReactionUnavailabilityReasonGuest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode reactionUnavailabilityReasonGuest#50ef5244 to nil")
	}
	if err := b.ConsumeID(ReactionUnavailabilityReasonGuestTypeID); err != nil {
		return fmt.Errorf("unable to decode reactionUnavailabilityReasonGuest#50ef5244: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *ReactionUnavailabilityReasonGuest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode reactionUnavailabilityReasonGuest#50ef5244 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *ReactionUnavailabilityReasonGuest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode reactionUnavailabilityReasonGuest#50ef5244 as nil")
	}
	b.ObjStart()
	b.PutID("reactionUnavailabilityReasonGuest")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *ReactionUnavailabilityReasonGuest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode reactionUnavailabilityReasonGuest#50ef5244 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("reactionUnavailabilityReasonGuest"); err != nil {
				return fmt.Errorf("unable to decode reactionUnavailabilityReasonGuest#50ef5244: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// ReactionUnavailabilityReasonClassName is schema name of ReactionUnavailabilityReasonClass.
const ReactionUnavailabilityReasonClassName = "ReactionUnavailabilityReason"

// ReactionUnavailabilityReasonClass represents ReactionUnavailabilityReason generic type.
//
// Example:
//
//	g, err := tdapi.DecodeReactionUnavailabilityReason(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.ReactionUnavailabilityReasonAnonymousAdministrator: // reactionUnavailabilityReasonAnonymousAdministrator#e23883fb
//	case *tdapi.ReactionUnavailabilityReasonGuest: // reactionUnavailabilityReasonGuest#50ef5244
//	default: panic(v)
//	}
type ReactionUnavailabilityReasonClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ReactionUnavailabilityReasonClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	EncodeTDLibJSON(b tdjson.Encoder) error
	DecodeTDLibJSON(b tdjson.Decoder) error
}

// DecodeReactionUnavailabilityReason implements binary de-serialization for ReactionUnavailabilityReasonClass.
func DecodeReactionUnavailabilityReason(buf *bin.Buffer) (ReactionUnavailabilityReasonClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case ReactionUnavailabilityReasonAnonymousAdministratorTypeID:
		// Decoding reactionUnavailabilityReasonAnonymousAdministrator#e23883fb.
		v := ReactionUnavailabilityReasonAnonymousAdministrator{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ReactionUnavailabilityReasonClass: %w", err)
		}
		return &v, nil
	case ReactionUnavailabilityReasonGuestTypeID:
		// Decoding reactionUnavailabilityReasonGuest#50ef5244.
		v := ReactionUnavailabilityReasonGuest{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ReactionUnavailabilityReasonClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode ReactionUnavailabilityReasonClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONReactionUnavailabilityReason implements binary de-serialization for ReactionUnavailabilityReasonClass.
func DecodeTDLibJSONReactionUnavailabilityReason(buf tdjson.Decoder) (ReactionUnavailabilityReasonClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "reactionUnavailabilityReasonAnonymousAdministrator":
		// Decoding reactionUnavailabilityReasonAnonymousAdministrator#e23883fb.
		v := ReactionUnavailabilityReasonAnonymousAdministrator{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ReactionUnavailabilityReasonClass: %w", err)
		}
		return &v, nil
	case "reactionUnavailabilityReasonGuest":
		// Decoding reactionUnavailabilityReasonGuest#50ef5244.
		v := ReactionUnavailabilityReasonGuest{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode ReactionUnavailabilityReasonClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode ReactionUnavailabilityReasonClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// ReactionUnavailabilityReason boxes the ReactionUnavailabilityReasonClass providing a helper.
type ReactionUnavailabilityReasonBox struct {
	ReactionUnavailabilityReason ReactionUnavailabilityReasonClass
}

// Decode implements bin.Decoder for ReactionUnavailabilityReasonBox.
func (b *ReactionUnavailabilityReasonBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode ReactionUnavailabilityReasonBox to nil")
	}
	v, err := DecodeReactionUnavailabilityReason(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.ReactionUnavailabilityReason = v
	return nil
}

// Encode implements bin.Encode for ReactionUnavailabilityReasonBox.
func (b *ReactionUnavailabilityReasonBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.ReactionUnavailabilityReason == nil {
		return fmt.Errorf("unable to encode ReactionUnavailabilityReasonClass as nil")
	}
	return b.ReactionUnavailabilityReason.Encode(buf)
}

// DecodeTDLibJSON implements bin.Decoder for ReactionUnavailabilityReasonBox.
func (b *ReactionUnavailabilityReasonBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("unable to decode ReactionUnavailabilityReasonBox to nil")
	}
	v, err := DecodeTDLibJSONReactionUnavailabilityReason(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.ReactionUnavailabilityReason = v
	return nil
}

// EncodeTDLibJSON implements bin.Encode for ReactionUnavailabilityReasonBox.
func (b *ReactionUnavailabilityReasonBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil || b.ReactionUnavailabilityReason == nil {
		return fmt.Errorf("unable to encode ReactionUnavailabilityReasonClass as nil")
	}
	return b.ReactionUnavailabilityReason.EncodeTDLibJSON(buf)
}
