// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// MessagesGetEmojiStickerGroupsRequest represents TL type `messages.getEmojiStickerGroups#1dd840f5`.
// Represents a list of emoji categories¹, to be used when choosing a sticker.
//
// Links:
//  1. https://core.telegram.org/api/emoji-categories
//
// See https://core.telegram.org/method/messages.getEmojiStickerGroups for reference.
type MessagesGetEmojiStickerGroupsRequest struct {
	// Hash used for caching, for more info click here¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	Hash int
}

// MessagesGetEmojiStickerGroupsRequestTypeID is TL type id of MessagesGetEmojiStickerGroupsRequest.
const MessagesGetEmojiStickerGroupsRequestTypeID = 0x1dd840f5

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

func (g *MessagesGetEmojiStickerGroupsRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesGetEmojiStickerGroupsRequest from given interface.
func (g *MessagesGetEmojiStickerGroupsRequest) FillFrom(from interface {
	GetHash() (value int)
}) {
	g.Hash = from.GetHash()
}

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

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

// TypeInfo returns info about TL type.
func (g *MessagesGetEmojiStickerGroupsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.getEmojiStickerGroups",
		ID:   MessagesGetEmojiStickerGroupsRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *MessagesGetEmojiStickerGroupsRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getEmojiStickerGroups#1dd840f5 as nil")
	}
	b.PutID(MessagesGetEmojiStickerGroupsRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *MessagesGetEmojiStickerGroupsRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getEmojiStickerGroups#1dd840f5 as nil")
	}
	b.PutInt(g.Hash)
	return nil
}

// Decode implements bin.Decoder.
func (g *MessagesGetEmojiStickerGroupsRequest) Decode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode messages.getEmojiStickerGroups#1dd840f5 to nil")
	}
	if err := b.ConsumeID(MessagesGetEmojiStickerGroupsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.getEmojiStickerGroups#1dd840f5: %w", err)
	}
	return g.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (g *MessagesGetEmojiStickerGroupsRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode messages.getEmojiStickerGroups#1dd840f5 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.getEmojiStickerGroups#1dd840f5: field hash: %w", err)
		}
		g.Hash = value
	}
	return nil
}

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

// MessagesGetEmojiStickerGroups invokes method messages.getEmojiStickerGroups#1dd840f5 returning error if any.
// Represents a list of emoji categories¹, to be used when choosing a sticker.
//
// Links:
//  1. https://core.telegram.org/api/emoji-categories
//
// See https://core.telegram.org/method/messages.getEmojiStickerGroups for reference.
func (c *Client) MessagesGetEmojiStickerGroups(ctx context.Context, hash int) (MessagesEmojiGroupsClass, error) {
	var result MessagesEmojiGroupsBox

	request := &MessagesGetEmojiStickerGroupsRequest{
		Hash: hash,
	}
	if err := c.rpc.Invoke(ctx, request, &result); err != nil {
		return nil, err
	}
	return result.EmojiGroups, nil
}
