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

// GetEmojiReactionRequest represents TL type `getEmojiReaction#e53411dc`.
type GetEmojiReactionRequest struct {
	// Text representation of the reaction
	Emoji string
}

// GetEmojiReactionRequestTypeID is TL type id of GetEmojiReactionRequest.
const GetEmojiReactionRequestTypeID = 0xe53411dc

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

func (g *GetEmojiReactionRequest) Zero() bool {
	if g == nil {
		return true
	}
	if !(g.Emoji == "") {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (g *GetEmojiReactionRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "getEmojiReaction",
		ID:   GetEmojiReactionRequestTypeID,
	}
	if g == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Emoji",
			SchemaName: "emoji",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (g *GetEmojiReactionRequest) Encode(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getEmojiReaction#e53411dc as nil")
	}
	b.PutID(GetEmojiReactionRequestTypeID)
	return g.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (g *GetEmojiReactionRequest) EncodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't encode getEmojiReaction#e53411dc as nil")
	}
	b.PutString(g.Emoji)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (g *GetEmojiReactionRequest) DecodeBare(b *bin.Buffer) error {
	if g == nil {
		return fmt.Errorf("can't decode getEmojiReaction#e53411dc to nil")
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode getEmojiReaction#e53411dc: field emoji: %w", err)
		}
		g.Emoji = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (g *GetEmojiReactionRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if g == nil {
		return fmt.Errorf("can't encode getEmojiReaction#e53411dc as nil")
	}
	b.ObjStart()
	b.PutID("getEmojiReaction")
	b.Comma()
	b.FieldStart("emoji")
	b.PutString(g.Emoji)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (g *GetEmojiReactionRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if g == nil {
		return fmt.Errorf("can't decode getEmojiReaction#e53411dc to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("getEmojiReaction"); err != nil {
				return fmt.Errorf("unable to decode getEmojiReaction#e53411dc: %w", err)
			}
		case "emoji":
			value, err := b.String()
			if err != nil {
				return fmt.Errorf("unable to decode getEmojiReaction#e53411dc: field emoji: %w", err)
			}
			g.Emoji = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetEmoji returns value of Emoji field.
func (g *GetEmojiReactionRequest) GetEmoji() (value string) {
	if g == nil {
		return
	}
	return g.Emoji
}

// GetEmojiReaction invokes method getEmojiReaction#e53411dc returning error if any.
func (c *Client) GetEmojiReaction(ctx context.Context, emoji string) (*EmojiReaction, error) {
	var result EmojiReaction

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