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

// EmojiStatusCustomEmojis represents TL type `emojiStatusCustomEmojis#b2b726af`.
type EmojiStatusCustomEmojis struct {
	// The list of custom emoji identifiers
	CustomEmojiIDs []int64
}

// EmojiStatusCustomEmojisTypeID is TL type id of EmojiStatusCustomEmojis.
const EmojiStatusCustomEmojisTypeID = 0xb2b726af

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

func (e *EmojiStatusCustomEmojis) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.CustomEmojiIDs == nil) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (e *EmojiStatusCustomEmojis) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "emojiStatusCustomEmojis",
		ID:   EmojiStatusCustomEmojisTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "CustomEmojiIDs",
			SchemaName: "custom_emoji_ids",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *EmojiStatusCustomEmojis) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiStatusCustomEmojis#b2b726af as nil")
	}
	b.PutID(EmojiStatusCustomEmojisTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *EmojiStatusCustomEmojis) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiStatusCustomEmojis#b2b726af as nil")
	}
	b.PutInt(len(e.CustomEmojiIDs))
	for _, v := range e.CustomEmojiIDs {
		b.PutLong(v)
	}
	return nil
}

// Decode implements bin.Decoder.
func (e *EmojiStatusCustomEmojis) Decode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode emojiStatusCustomEmojis#b2b726af to nil")
	}
	if err := b.ConsumeID(EmojiStatusCustomEmojisTypeID); err != nil {
		return fmt.Errorf("unable to decode emojiStatusCustomEmojis#b2b726af: %w", err)
	}
	return e.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (e *EmojiStatusCustomEmojis) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode emojiStatusCustomEmojis#b2b726af to nil")
	}
	{
		headerLen, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode emojiStatusCustomEmojis#b2b726af: field custom_emoji_ids: %w", err)
		}

		if headerLen > 0 {
			e.CustomEmojiIDs = make([]int64, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Long()
			if err != nil {
				return fmt.Errorf("unable to decode emojiStatusCustomEmojis#b2b726af: field custom_emoji_ids: %w", err)
			}
			e.CustomEmojiIDs = append(e.CustomEmojiIDs, value)
		}
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (e *EmojiStatusCustomEmojis) EncodeTDLibJSON(b tdjson.Encoder) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiStatusCustomEmojis#b2b726af as nil")
	}
	b.ObjStart()
	b.PutID("emojiStatusCustomEmojis")
	b.Comma()
	b.FieldStart("custom_emoji_ids")
	b.ArrStart()
	for _, v := range e.CustomEmojiIDs {
		b.PutLong(v)
		b.Comma()
	}
	b.StripComma()
	b.ArrEnd()
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (e *EmojiStatusCustomEmojis) DecodeTDLibJSON(b tdjson.Decoder) error {
	if e == nil {
		return fmt.Errorf("can't decode emojiStatusCustomEmojis#b2b726af to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("emojiStatusCustomEmojis"); err != nil {
				return fmt.Errorf("unable to decode emojiStatusCustomEmojis#b2b726af: %w", err)
			}
		case "custom_emoji_ids":
			if err := b.Arr(func(b tdjson.Decoder) error {
				value, err := b.Long()
				if err != nil {
					return fmt.Errorf("unable to decode emojiStatusCustomEmojis#b2b726af: field custom_emoji_ids: %w", err)
				}
				e.CustomEmojiIDs = append(e.CustomEmojiIDs, value)
				return nil
			}); err != nil {
				return fmt.Errorf("unable to decode emojiStatusCustomEmojis#b2b726af: field custom_emoji_ids: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetCustomEmojiIDs returns value of CustomEmojiIDs field.
func (e *EmojiStatusCustomEmojis) GetCustomEmojiIDs() (value []int64) {
	if e == nil {
		return
	}
	return e.CustomEmojiIDs
}
