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

// EmojiGroup represents TL type `emojiGroup#7a9abda9`.
// Represents an emoji category¹.
//
// Links:
//  1. https://core.telegram.org/api/custom-emoji#emoji-categories
//
// See https://core.telegram.org/constructor/emojiGroup for reference.
type EmojiGroup struct {
	// Category name, i.e. "Animals", "Flags", "Faces" and so on...
	Title string
	// A single custom emoji used as preview for the category.
	IconEmojiID int64
	// A list of UTF-8 emojis, matching the category.
	Emoticons []string
}

// EmojiGroupTypeID is TL type id of EmojiGroup.
const EmojiGroupTypeID = 0x7a9abda9

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

func (e *EmojiGroup) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.Title == "") {
		return false
	}
	if !(e.IconEmojiID == 0) {
		return false
	}
	if !(e.Emoticons == nil) {
		return false
	}

	return true
}

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

// FillFrom fills EmojiGroup from given interface.
func (e *EmojiGroup) FillFrom(from interface {
	GetTitle() (value string)
	GetIconEmojiID() (value int64)
	GetEmoticons() (value []string)
}) {
	e.Title = from.GetTitle()
	e.IconEmojiID = from.GetIconEmojiID()
	e.Emoticons = from.GetEmoticons()
}

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

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

// TypeInfo returns info about TL type.
func (e *EmojiGroup) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "emojiGroup",
		ID:   EmojiGroupTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "IconEmojiID",
			SchemaName: "icon_emoji_id",
		},
		{
			Name:       "Emoticons",
			SchemaName: "emoticons",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *EmojiGroup) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiGroup#7a9abda9 as nil")
	}
	b.PutID(EmojiGroupTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *EmojiGroup) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode emojiGroup#7a9abda9 as nil")
	}
	b.PutString(e.Title)
	b.PutLong(e.IconEmojiID)
	b.PutVectorHeader(len(e.Emoticons))
	for _, v := range e.Emoticons {
		b.PutString(v)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (e *EmojiGroup) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode emojiGroup#7a9abda9 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode emojiGroup#7a9abda9: field title: %w", err)
		}
		e.Title = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode emojiGroup#7a9abda9: field icon_emoji_id: %w", err)
		}
		e.IconEmojiID = value
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode emojiGroup#7a9abda9: field emoticons: %w", err)
		}

		if headerLen > 0 {
			e.Emoticons = make([]string, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode emojiGroup#7a9abda9: field emoticons: %w", err)
			}
			e.Emoticons = append(e.Emoticons, value)
		}
	}
	return nil
}

// GetTitle returns value of Title field.
func (e *EmojiGroup) GetTitle() (value string) {
	if e == nil {
		return
	}
	return e.Title
}

// GetIconEmojiID returns value of IconEmojiID field.
func (e *EmojiGroup) GetIconEmojiID() (value int64) {
	if e == nil {
		return
	}
	return e.IconEmojiID
}

// GetEmoticons returns value of Emoticons field.
func (e *EmojiGroup) GetEmoticons() (value []string) {
	if e == nil {
		return
	}
	return e.Emoticons
}
