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

// MessagesDeletePollAnswerRequest represents TL type `messages.deletePollAnswer#ac8505a5`.
//
// See https://core.telegram.org/method/messages.deletePollAnswer for reference.
type MessagesDeletePollAnswerRequest struct {
	// Peer field of MessagesDeletePollAnswerRequest.
	Peer InputPeerClass
	// MsgID field of MessagesDeletePollAnswerRequest.
	MsgID int
	// Option field of MessagesDeletePollAnswerRequest.
	Option []byte
}

// MessagesDeletePollAnswerRequestTypeID is TL type id of MessagesDeletePollAnswerRequest.
const MessagesDeletePollAnswerRequestTypeID = 0xac8505a5

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

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

	return true
}

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

// FillFrom fills MessagesDeletePollAnswerRequest from given interface.
func (d *MessagesDeletePollAnswerRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetMsgID() (value int)
	GetOption() (value []byte)
}) {
	d.Peer = from.GetPeer()
	d.MsgID = from.GetMsgID()
	d.Option = from.GetOption()
}

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

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

// TypeInfo returns info about TL type.
func (d *MessagesDeletePollAnswerRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.deletePollAnswer",
		ID:   MessagesDeletePollAnswerRequestTypeID,
	}
	if d == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "MsgID",
			SchemaName: "msg_id",
		},
		{
			Name:       "Option",
			SchemaName: "option",
		},
	}
	return typ
}

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

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

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

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

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

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

// GetOption returns value of Option field.
func (d *MessagesDeletePollAnswerRequest) GetOption() (value []byte) {
	if d == nil {
		return
	}
	return d.Option
}

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

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