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

// MessagesGetDefaultTagReactionsRequest represents TL type `messages.getDefaultTagReactions#bdf93428`.
// Fetch a default recommended list of saved message tag reactions¹.
//
// Links:
//  1. https://core.telegram.org/api/saved-messages#tags
//
// See https://core.telegram.org/method/messages.getDefaultTagReactions for reference.
type MessagesGetDefaultTagReactionsRequest struct {
	// Hash used for caching, for more info click here¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	Hash int64
}

// MessagesGetDefaultTagReactionsRequestTypeID is TL type id of MessagesGetDefaultTagReactionsRequest.
const MessagesGetDefaultTagReactionsRequestTypeID = 0xbdf93428

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

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

	return true
}

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

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

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

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

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

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

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

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

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

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

// MessagesGetDefaultTagReactions invokes method messages.getDefaultTagReactions#bdf93428 returning error if any.
// Fetch a default recommended list of saved message tag reactions¹.
//
// Links:
//  1. https://core.telegram.org/api/saved-messages#tags
//
// See https://core.telegram.org/method/messages.getDefaultTagReactions for reference.
func (c *Client) MessagesGetDefaultTagReactions(ctx context.Context, hash int64) (MessagesReactionsClass, error) {
	var result MessagesReactionsBox

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