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

// MessagesGetStickersRequest represents TL type `messages.getStickers#d5a5d3a1`.
// Get stickers by emoji
//
// See https://core.telegram.org/method/messages.getStickers for reference.
type MessagesGetStickersRequest struct {
	// The emoji
	Emoticon string
	// Hash used for caching, for more info click here¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	Hash int64
}

// MessagesGetStickersRequestTypeID is TL type id of MessagesGetStickersRequest.
const MessagesGetStickersRequestTypeID = 0xd5a5d3a1

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

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

	return true
}

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

// FillFrom fills MessagesGetStickersRequest from given interface.
func (g *MessagesGetStickersRequest) FillFrom(from interface {
	GetEmoticon() (value string)
	GetHash() (value int64)
}) {
	g.Emoticon = from.GetEmoticon()
	g.Hash = from.GetHash()
}

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

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

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

// Encode implements bin.Encoder.
func (g *MessagesGetStickersRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getStickers#d5a5d3a1 as nil")
	}
	b.PutID(MessagesGetStickersRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *MessagesGetStickersRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode messages.getStickers#d5a5d3a1 as nil")
	}
	b.PutString(g.Emoticon)
	b.PutLong(g.Hash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *MessagesGetStickersRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode messages.getStickers#d5a5d3a1 to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.getStickers#d5a5d3a1: field emoticon: %w", err)
		}
		g.Emoticon = value
	}
	{
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode messages.getStickers#d5a5d3a1: field hash: %w", err)
		}
		g.Hash = value
	}
	return nil
}

// GetEmoticon returns value of Emoticon field.
func (g *MessagesGetStickersRequest) GetEmoticon() (value string) {
	if g == nil {
		return
	}
	return g.Emoticon
}

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

// MessagesGetStickers invokes method messages.getStickers#d5a5d3a1 returning error if any.
// Get stickers by emoji
//
// Possible errors:
//
//	400 EMOTICON_EMPTY: The emoji is empty.
//
// See https://core.telegram.org/method/messages.getStickers for reference.
func (c *Client) MessagesGetStickers(ctx context.Context, request *MessagesGetStickersRequest) (MessagesStickersClass, error) {
	var result MessagesStickersBox

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