// Code generated by gotdgen, DO NOT EDIT.

package tg

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

	"go.uber.org/multierr"

	"github.com/gotd/td/bin"
	"github.com/gotd/td/tdjson"
	"github.com/gotd/td/tdp"
	"github.com/gotd/td/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{}
)

// MessagesAvailableReactionsNotModified represents TL type `messages.availableReactionsNotModified#9f071957`.
// No new reactions are available
//
// See https://core.telegram.org/constructor/messages.availableReactionsNotModified for reference.
type MessagesAvailableReactionsNotModified struct {
}

// MessagesAvailableReactionsNotModifiedTypeID is TL type id of MessagesAvailableReactionsNotModified.
const MessagesAvailableReactionsNotModifiedTypeID = 0x9f071957

// construct implements constructor of MessagesAvailableReactionsClass.
func (a MessagesAvailableReactionsNotModified) construct() MessagesAvailableReactionsClass { return &a }

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

	_ MessagesAvailableReactionsClass = &MessagesAvailableReactionsNotModified{}
)

func (a *MessagesAvailableReactionsNotModified) Zero() bool {
	if a == nil {
		return true
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*MessagesAvailableReactionsNotModified) TypeName() string {
	return "messages.availableReactionsNotModified"
}

// TypeInfo returns info about TL type.
func (a *MessagesAvailableReactionsNotModified) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.availableReactionsNotModified",
		ID:   MessagesAvailableReactionsNotModifiedTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (a *MessagesAvailableReactionsNotModified) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode messages.availableReactionsNotModified#9f071957 as nil")
	}
	b.PutID(MessagesAvailableReactionsNotModifiedTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *MessagesAvailableReactionsNotModified) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode messages.availableReactionsNotModified#9f071957 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (a *MessagesAvailableReactionsNotModified) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode messages.availableReactionsNotModified#9f071957 to nil")
	}
	if err := b.ConsumeID(MessagesAvailableReactionsNotModifiedTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.availableReactionsNotModified#9f071957: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *MessagesAvailableReactionsNotModified) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode messages.availableReactionsNotModified#9f071957 to nil")
	}
	return nil
}

// MessagesAvailableReactions represents TL type `messages.availableReactions#768e3aad`.
// Animations and metadata associated with message reactions »¹
//
// Links:
//  1. https://core.telegram.org/api/reactions
//
// See https://core.telegram.org/constructor/messages.availableReactions for reference.
type MessagesAvailableReactions struct {
	// Hash for pagination, for more info click here¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	Hash int
	// Animations and metadata associated with message reactions »¹
	//
	// Links:
	//  1) https://core.telegram.org/api/reactions
	Reactions []AvailableReaction
}

// MessagesAvailableReactionsTypeID is TL type id of MessagesAvailableReactions.
const MessagesAvailableReactionsTypeID = 0x768e3aad

// construct implements constructor of MessagesAvailableReactionsClass.
func (a MessagesAvailableReactions) construct() MessagesAvailableReactionsClass { return &a }

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

	_ MessagesAvailableReactionsClass = &MessagesAvailableReactions{}
)

func (a *MessagesAvailableReactions) Zero() bool {
	if a == nil {
		return true
	}
	if !(a.Hash == 0) {
		return false
	}
	if !(a.Reactions == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesAvailableReactions from given interface.
func (a *MessagesAvailableReactions) FillFrom(from interface {
	GetHash() (value int)
	GetReactions() (value []AvailableReaction)
}) {
	a.Hash = from.GetHash()
	a.Reactions = from.GetReactions()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesAvailableReactions) TypeName() string {
	return "messages.availableReactions"
}

// TypeInfo returns info about TL type.
func (a *MessagesAvailableReactions) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.availableReactions",
		ID:   MessagesAvailableReactionsTypeID,
	}
	if a == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
		{
			Name:       "Reactions",
			SchemaName: "reactions",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (a *MessagesAvailableReactions) Encode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode messages.availableReactions#768e3aad as nil")
	}
	b.PutID(MessagesAvailableReactionsTypeID)
	return a.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (a *MessagesAvailableReactions) EncodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't encode messages.availableReactions#768e3aad as nil")
	}
	b.PutInt(a.Hash)
	b.PutVectorHeader(len(a.Reactions))
	for idx, v := range a.Reactions {
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.availableReactions#768e3aad: field reactions element with index %d: %w", idx, err)
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func (a *MessagesAvailableReactions) Decode(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode messages.availableReactions#768e3aad to nil")
	}
	if err := b.ConsumeID(MessagesAvailableReactionsTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.availableReactions#768e3aad: %w", err)
	}
	return a.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (a *MessagesAvailableReactions) DecodeBare(b *bin.Buffer) error {
	if a == nil {
		return fmt.Errorf("can't decode messages.availableReactions#768e3aad to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.availableReactions#768e3aad: field hash: %w", err)
		}
		a.Hash = value
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.availableReactions#768e3aad: field reactions: %w", err)
		}

		if headerLen > 0 {
			a.Reactions = make([]AvailableReaction, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			var value AvailableReaction
			if err := value.Decode(b); err != nil {
				return fmt.Errorf("unable to decode messages.availableReactions#768e3aad: field reactions: %w", err)
			}
			a.Reactions = append(a.Reactions, value)
		}
	}
	return nil
}

// GetHash returns value of Hash field.
func (a *MessagesAvailableReactions) GetHash() (value int) {
	if a == nil {
		return
	}
	return a.Hash
}

// GetReactions returns value of Reactions field.
func (a *MessagesAvailableReactions) GetReactions() (value []AvailableReaction) {
	if a == nil {
		return
	}
	return a.Reactions
}

// MessagesAvailableReactionsClassName is schema name of MessagesAvailableReactionsClass.
const MessagesAvailableReactionsClassName = "messages.AvailableReactions"

// MessagesAvailableReactionsClass represents messages.AvailableReactions generic type.
//
// See https://core.telegram.org/type/messages.AvailableReactions for reference.
//
// Example:
//
//	g, err := tg.DecodeMessagesAvailableReactions(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.MessagesAvailableReactionsNotModified: // messages.availableReactionsNotModified#9f071957
//	case *tg.MessagesAvailableReactions: // messages.availableReactions#768e3aad
//	default: panic(v)
//	}
type MessagesAvailableReactionsClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MessagesAvailableReactionsClass

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

	// AsModified tries to map MessagesAvailableReactionsClass to MessagesAvailableReactions.
	AsModified() (*MessagesAvailableReactions, bool)
}

// AsModified tries to map MessagesAvailableReactionsNotModified to MessagesAvailableReactions.
func (a *MessagesAvailableReactionsNotModified) AsModified() (*MessagesAvailableReactions, bool) {
	return nil, false
}

// AsModified tries to map MessagesAvailableReactions to MessagesAvailableReactions.
func (a *MessagesAvailableReactions) AsModified() (*MessagesAvailableReactions, bool) {
	return a, true
}

// DecodeMessagesAvailableReactions implements binary de-serialization for MessagesAvailableReactionsClass.
func DecodeMessagesAvailableReactions(buf *bin.Buffer) (MessagesAvailableReactionsClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case MessagesAvailableReactionsNotModifiedTypeID:
		// Decoding messages.availableReactionsNotModified#9f071957.
		v := MessagesAvailableReactionsNotModified{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessagesAvailableReactionsClass: %w", err)
		}
		return &v, nil
	case MessagesAvailableReactionsTypeID:
		// Decoding messages.availableReactions#768e3aad.
		v := MessagesAvailableReactions{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessagesAvailableReactionsClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode MessagesAvailableReactionsClass: %w", bin.NewUnexpectedID(id))
	}
}

// MessagesAvailableReactions boxes the MessagesAvailableReactionsClass providing a helper.
type MessagesAvailableReactionsBox struct {
	AvailableReactions MessagesAvailableReactionsClass
}

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

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