// 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{}
)

// MessageEffectTypeEmojiReaction represents TL type `messageEffectTypeEmojiReaction#68aba63e`.
type MessageEffectTypeEmojiReaction struct {
	// Select animation for the effect in TGS format
	SelectAnimation Sticker
	// Effect animation for the effect in TGS format
	EffectAnimation Sticker
}

// MessageEffectTypeEmojiReactionTypeID is TL type id of MessageEffectTypeEmojiReaction.
const MessageEffectTypeEmojiReactionTypeID = 0x68aba63e

// construct implements constructor of MessageEffectTypeClass.
func (m MessageEffectTypeEmojiReaction) construct() MessageEffectTypeClass { return &m }

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

	_ MessageEffectTypeClass = &MessageEffectTypeEmojiReaction{}
)

func (m *MessageEffectTypeEmojiReaction) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.SelectAnimation.Zero()) {
		return false
	}
	if !(m.EffectAnimation.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (m *MessageEffectTypeEmojiReaction) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageEffectTypeEmojiReaction",
		ID:   MessageEffectTypeEmojiReactionTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "SelectAnimation",
			SchemaName: "select_animation",
		},
		{
			Name:       "EffectAnimation",
			SchemaName: "effect_animation",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (m *MessageEffectTypeEmojiReaction) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageEffectTypeEmojiReaction#68aba63e as nil")
	}
	b.PutID(MessageEffectTypeEmojiReactionTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageEffectTypeEmojiReaction) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageEffectTypeEmojiReaction#68aba63e as nil")
	}
	if err := m.SelectAnimation.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageEffectTypeEmojiReaction#68aba63e: field select_animation: %w", err)
	}
	if err := m.EffectAnimation.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageEffectTypeEmojiReaction#68aba63e: field effect_animation: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MessageEffectTypeEmojiReaction) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageEffectTypeEmojiReaction#68aba63e to nil")
	}
	if err := b.ConsumeID(MessageEffectTypeEmojiReactionTypeID); err != nil {
		return fmt.Errorf("unable to decode messageEffectTypeEmojiReaction#68aba63e: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MessageEffectTypeEmojiReaction) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageEffectTypeEmojiReaction#68aba63e to nil")
	}
	{
		if err := m.SelectAnimation.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageEffectTypeEmojiReaction#68aba63e: field select_animation: %w", err)
		}
	}
	{
		if err := m.EffectAnimation.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageEffectTypeEmojiReaction#68aba63e: field effect_animation: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (m *MessageEffectTypeEmojiReaction) EncodeTDLibJSON(b tdjson.Encoder) error {
	if m == nil {
		return fmt.Errorf("can't encode messageEffectTypeEmojiReaction#68aba63e as nil")
	}
	b.ObjStart()
	b.PutID("messageEffectTypeEmojiReaction")
	b.Comma()
	b.FieldStart("select_animation")
	if err := m.SelectAnimation.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode messageEffectTypeEmojiReaction#68aba63e: field select_animation: %w", err)
	}
	b.Comma()
	b.FieldStart("effect_animation")
	if err := m.EffectAnimation.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode messageEffectTypeEmojiReaction#68aba63e: field effect_animation: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (m *MessageEffectTypeEmojiReaction) DecodeTDLibJSON(b tdjson.Decoder) error {
	if m == nil {
		return fmt.Errorf("can't decode messageEffectTypeEmojiReaction#68aba63e to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("messageEffectTypeEmojiReaction"); err != nil {
				return fmt.Errorf("unable to decode messageEffectTypeEmojiReaction#68aba63e: %w", err)
			}
		case "select_animation":
			if err := m.SelectAnimation.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode messageEffectTypeEmojiReaction#68aba63e: field select_animation: %w", err)
			}
		case "effect_animation":
			if err := m.EffectAnimation.DecodeTDLibJSON(b); err != nil {
				return fmt.Errorf("unable to decode messageEffectTypeEmojiReaction#68aba63e: field effect_animation: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetSelectAnimation returns value of SelectAnimation field.
func (m *MessageEffectTypeEmojiReaction) GetSelectAnimation() (value Sticker) {
	if m == nil {
		return
	}
	return m.SelectAnimation
}

// GetEffectAnimation returns value of EffectAnimation field.
func (m *MessageEffectTypeEmojiReaction) GetEffectAnimation() (value Sticker) {
	if m == nil {
		return
	}
	return m.EffectAnimation
}

// MessageEffectTypePremiumSticker represents TL type `messageEffectTypePremiumSticker#61962bf9`.
type MessageEffectTypePremiumSticker struct {
	// The premium sticker. The effect can be found at sticker.full_type.premium_animation
	Sticker Sticker
}

// MessageEffectTypePremiumStickerTypeID is TL type id of MessageEffectTypePremiumSticker.
const MessageEffectTypePremiumStickerTypeID = 0x61962bf9

// construct implements constructor of MessageEffectTypeClass.
func (m MessageEffectTypePremiumSticker) construct() MessageEffectTypeClass { return &m }

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

	_ MessageEffectTypeClass = &MessageEffectTypePremiumSticker{}
)

func (m *MessageEffectTypePremiumSticker) Zero() bool {
	if m == nil {
		return true
	}
	if !(m.Sticker.Zero()) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (m *MessageEffectTypePremiumSticker) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messageEffectTypePremiumSticker",
		ID:   MessageEffectTypePremiumStickerTypeID,
	}
	if m == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Sticker",
			SchemaName: "sticker",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (m *MessageEffectTypePremiumSticker) Encode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageEffectTypePremiumSticker#61962bf9 as nil")
	}
	b.PutID(MessageEffectTypePremiumStickerTypeID)
	return m.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (m *MessageEffectTypePremiumSticker) EncodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't encode messageEffectTypePremiumSticker#61962bf9 as nil")
	}
	if err := m.Sticker.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messageEffectTypePremiumSticker#61962bf9: field sticker: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (m *MessageEffectTypePremiumSticker) Decode(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageEffectTypePremiumSticker#61962bf9 to nil")
	}
	if err := b.ConsumeID(MessageEffectTypePremiumStickerTypeID); err != nil {
		return fmt.Errorf("unable to decode messageEffectTypePremiumSticker#61962bf9: %w", err)
	}
	return m.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (m *MessageEffectTypePremiumSticker) DecodeBare(b *bin.Buffer) error {
	if m == nil {
		return fmt.Errorf("can't decode messageEffectTypePremiumSticker#61962bf9 to nil")
	}
	{
		if err := m.Sticker.Decode(b); err != nil {
			return fmt.Errorf("unable to decode messageEffectTypePremiumSticker#61962bf9: field sticker: %w", err)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (m *MessageEffectTypePremiumSticker) EncodeTDLibJSON(b tdjson.Encoder) error {
	if m == nil {
		return fmt.Errorf("can't encode messageEffectTypePremiumSticker#61962bf9 as nil")
	}
	b.ObjStart()
	b.PutID("messageEffectTypePremiumSticker")
	b.Comma()
	b.FieldStart("sticker")
	if err := m.Sticker.EncodeTDLibJSON(b); err != nil {
		return fmt.Errorf("unable to encode messageEffectTypePremiumSticker#61962bf9: field sticker: %w", err)
	}
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (m *MessageEffectTypePremiumSticker) DecodeTDLibJSON(b tdjson.Decoder) error {
	if m == nil {
		return fmt.Errorf("can't decode messageEffectTypePremiumSticker#61962bf9 to nil")
	}

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

// GetSticker returns value of Sticker field.
func (m *MessageEffectTypePremiumSticker) GetSticker() (value Sticker) {
	if m == nil {
		return
	}
	return m.Sticker
}

// MessageEffectTypeClassName is schema name of MessageEffectTypeClass.
const MessageEffectTypeClassName = "MessageEffectType"

// MessageEffectTypeClass represents MessageEffectType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeMessageEffectType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.MessageEffectTypeEmojiReaction: // messageEffectTypeEmojiReaction#68aba63e
//	case *tdapi.MessageEffectTypePremiumSticker: // messageEffectTypePremiumSticker#61962bf9
//	default: panic(v)
//	}
type MessageEffectTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MessageEffectTypeClass

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

// DecodeMessageEffectType implements binary de-serialization for MessageEffectTypeClass.
func DecodeMessageEffectType(buf *bin.Buffer) (MessageEffectTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case MessageEffectTypeEmojiReactionTypeID:
		// Decoding messageEffectTypeEmojiReaction#68aba63e.
		v := MessageEffectTypeEmojiReaction{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageEffectTypeClass: %w", err)
		}
		return &v, nil
	case MessageEffectTypePremiumStickerTypeID:
		// Decoding messageEffectTypePremiumSticker#61962bf9.
		v := MessageEffectTypePremiumSticker{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageEffectTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode MessageEffectTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONMessageEffectType implements binary de-serialization for MessageEffectTypeClass.
func DecodeTDLibJSONMessageEffectType(buf tdjson.Decoder) (MessageEffectTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "messageEffectTypeEmojiReaction":
		// Decoding messageEffectTypeEmojiReaction#68aba63e.
		v := MessageEffectTypeEmojiReaction{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageEffectTypeClass: %w", err)
		}
		return &v, nil
	case "messageEffectTypePremiumSticker":
		// Decoding messageEffectTypePremiumSticker#61962bf9.
		v := MessageEffectTypePremiumSticker{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessageEffectTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode MessageEffectTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// MessageEffectType boxes the MessageEffectTypeClass providing a helper.
type MessageEffectTypeBox struct {
	MessageEffectType MessageEffectTypeClass
}

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

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

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

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