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

// RemovePendingPaidMessageReactionsRequest represents TL type `removePendingPaidMessageReactions#41949cfb`.
type RemovePendingPaidMessageReactionsRequest struct {
	// Identifier of the chat to which the message belongs
	ChatID int64
	// Identifier of the message
	MessageID int64
}

// RemovePendingPaidMessageReactionsRequestTypeID is TL type id of RemovePendingPaidMessageReactionsRequest.
const RemovePendingPaidMessageReactionsRequestTypeID = 0x41949cfb

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

func (r *RemovePendingPaidMessageReactionsRequest) Zero() bool {
	if r == nil {
		return true
	}
	if !(r.ChatID == 0) {
		return false
	}
	if !(r.MessageID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *RemovePendingPaidMessageReactionsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "removePendingPaidMessageReactions",
		ID:   RemovePendingPaidMessageReactionsRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageID",
			SchemaName: "message_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *RemovePendingPaidMessageReactionsRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode removePendingPaidMessageReactions#41949cfb as nil")
	}
	b.PutID(RemovePendingPaidMessageReactionsRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *RemovePendingPaidMessageReactionsRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode removePendingPaidMessageReactions#41949cfb as nil")
	}
	b.PutInt53(r.ChatID)
	b.PutInt53(r.MessageID)
	return nil
}

// Decode implements bin.Decoder.
func (r *RemovePendingPaidMessageReactionsRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode removePendingPaidMessageReactions#41949cfb to nil")
	}
	if err := b.ConsumeID(RemovePendingPaidMessageReactionsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode removePendingPaidMessageReactions#41949cfb: %w", err)
	}
	return r.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (r *RemovePendingPaidMessageReactionsRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode removePendingPaidMessageReactions#41949cfb to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode removePendingPaidMessageReactions#41949cfb: field chat_id: %w", err)
		}
		r.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode removePendingPaidMessageReactions#41949cfb: field message_id: %w", err)
		}
		r.MessageID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *RemovePendingPaidMessageReactionsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode removePendingPaidMessageReactions#41949cfb as nil")
	}
	b.ObjStart()
	b.PutID("removePendingPaidMessageReactions")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(r.ChatID)
	b.Comma()
	b.FieldStart("message_id")
	b.PutInt53(r.MessageID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *RemovePendingPaidMessageReactionsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode removePendingPaidMessageReactions#41949cfb to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("removePendingPaidMessageReactions"); err != nil {
				return fmt.Errorf("unable to decode removePendingPaidMessageReactions#41949cfb: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode removePendingPaidMessageReactions#41949cfb: field chat_id: %w", err)
			}
			r.ChatID = value
		case "message_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode removePendingPaidMessageReactions#41949cfb: field message_id: %w", err)
			}
			r.MessageID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetChatID returns value of ChatID field.
func (r *RemovePendingPaidMessageReactionsRequest) GetChatID() (value int64) {
	if r == nil {
		return
	}
	return r.ChatID
}

// GetMessageID returns value of MessageID field.
func (r *RemovePendingPaidMessageReactionsRequest) GetMessageID() (value int64) {
	if r == nil {
		return
	}
	return r.MessageID
}

// RemovePendingPaidMessageReactions invokes method removePendingPaidMessageReactions#41949cfb returning error if any.
func (c *Client) RemovePendingPaidMessageReactions(ctx context.Context, request *RemovePendingPaidMessageReactionsRequest) error {
	var ok Ok

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