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

// MessagesDeleteParticipantReactionRequest represents TL type `messages.deleteParticipantReaction#e3b7f82c`.
//
// See https://core.telegram.org/method/messages.deleteParticipantReaction for reference.
type MessagesDeleteParticipantReactionRequest struct {
	// Peer field of MessagesDeleteParticipantReactionRequest.
	Peer InputPeerClass
	// MsgID field of MessagesDeleteParticipantReactionRequest.
	MsgID int
	// Participant field of MessagesDeleteParticipantReactionRequest.
	Participant InputPeerClass
}

// MessagesDeleteParticipantReactionRequestTypeID is TL type id of MessagesDeleteParticipantReactionRequest.
const MessagesDeleteParticipantReactionRequestTypeID = 0xe3b7f82c

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

func (d *MessagesDeleteParticipantReactionRequest) Zero() bool {
	if d == nil {
		return true
	}
	if !(d.Peer == nil) {
		return false
	}
	if !(d.MsgID == 0) {
		return false
	}
	if !(d.Participant == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesDeleteParticipantReactionRequest from given interface.
func (d *MessagesDeleteParticipantReactionRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetMsgID() (value int)
	GetParticipant() (value InputPeerClass)
}) {
	d.Peer = from.GetPeer()
	d.MsgID = from.GetMsgID()
	d.Participant = from.GetParticipant()
}

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

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

// TypeInfo returns info about TL type.
func (d *MessagesDeleteParticipantReactionRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.deleteParticipantReaction",
		ID:   MessagesDeleteParticipantReactionRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "MsgID",
			SchemaName: "msg_id",
		},
		{
			Name:       "Participant",
			SchemaName: "participant",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (d *MessagesDeleteParticipantReactionRequest) Encode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode messages.deleteParticipantReaction#e3b7f82c as nil")
	}
	b.PutID(MessagesDeleteParticipantReactionRequestTypeID)
	return d.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (d *MessagesDeleteParticipantReactionRequest) EncodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't encode messages.deleteParticipantReaction#e3b7f82c as nil")
	}
	if d.Peer == nil {
		return fmt.Errorf("unable to encode messages.deleteParticipantReaction#e3b7f82c: field peer is nil")
	}
	if err := d.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.deleteParticipantReaction#e3b7f82c: field peer: %w", err)
	}
	b.PutInt(d.MsgID)
	if d.Participant == nil {
		return fmt.Errorf("unable to encode messages.deleteParticipantReaction#e3b7f82c: field participant is nil")
	}
	if err := d.Participant.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.deleteParticipantReaction#e3b7f82c: field participant: %w", err)
	}
	return nil
}

// Decode implements bin.Decoder.
func (d *MessagesDeleteParticipantReactionRequest) Decode(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode messages.deleteParticipantReaction#e3b7f82c to nil")
	}
	if err := b.ConsumeID(MessagesDeleteParticipantReactionRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.deleteParticipantReaction#e3b7f82c: %w", err)
	}
	return d.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (d *MessagesDeleteParticipantReactionRequest) DecodeBare(b *bin.Buffer) error {
	if d == nil {
		return fmt.Errorf("can't decode messages.deleteParticipantReaction#e3b7f82c to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.deleteParticipantReaction#e3b7f82c: field peer: %w", err)
		}
		d.Peer = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.deleteParticipantReaction#e3b7f82c: field msg_id: %w", err)
		}
		d.MsgID = value
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.deleteParticipantReaction#e3b7f82c: field participant: %w", err)
		}
		d.Participant = value
	}
	return nil
}

// GetPeer returns value of Peer field.
func (d *MessagesDeleteParticipantReactionRequest) GetPeer() (value InputPeerClass) {
	if d == nil {
		return
	}
	return d.Peer
}

// GetMsgID returns value of MsgID field.
func (d *MessagesDeleteParticipantReactionRequest) GetMsgID() (value int) {
	if d == nil {
		return
	}
	return d.MsgID
}

// GetParticipant returns value of Participant field.
func (d *MessagesDeleteParticipantReactionRequest) GetParticipant() (value InputPeerClass) {
	if d == nil {
		return
	}
	return d.Participant
}

// MessagesDeleteParticipantReaction invokes method messages.deleteParticipantReaction#e3b7f82c returning error if any.
//
// See https://core.telegram.org/method/messages.deleteParticipantReaction for reference.
func (c *Client) MessagesDeleteParticipantReaction(ctx context.Context, request *MessagesDeleteParticipantReactionRequest) (UpdatesClass, error) {
	var result UpdatesBox

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