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

// MessagesEditChatParticipantRankRequest represents TL type `messages.editChatParticipantRank#a00f32b0`.
//
// See https://core.telegram.org/method/messages.editChatParticipantRank for reference.
type MessagesEditChatParticipantRankRequest struct {
	// Peer field of MessagesEditChatParticipantRankRequest.
	Peer InputPeerClass
	// Participant field of MessagesEditChatParticipantRankRequest.
	Participant InputPeerClass
	// Rank field of MessagesEditChatParticipantRankRequest.
	Rank string
}

// MessagesEditChatParticipantRankRequestTypeID is TL type id of MessagesEditChatParticipantRankRequest.
const MessagesEditChatParticipantRankRequestTypeID = 0xa00f32b0

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

func (e *MessagesEditChatParticipantRankRequest) Zero() bool {
	if e == nil {
		return true
	}
	if !(e.Peer == nil) {
		return false
	}
	if !(e.Participant == nil) {
		return false
	}
	if !(e.Rank == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesEditChatParticipantRankRequest from given interface.
func (e *MessagesEditChatParticipantRankRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetParticipant() (value InputPeerClass)
	GetRank() (value string)
}) {
	e.Peer = from.GetPeer()
	e.Participant = from.GetParticipant()
	e.Rank = from.GetRank()
}

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

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

// TypeInfo returns info about TL type.
func (e *MessagesEditChatParticipantRankRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.editChatParticipantRank",
		ID:   MessagesEditChatParticipantRankRequestTypeID,
	}
	if e == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Participant",
			SchemaName: "participant",
		},
		{
			Name:       "Rank",
			SchemaName: "rank",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (e *MessagesEditChatParticipantRankRequest) Encode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode messages.editChatParticipantRank#a00f32b0 as nil")
	}
	b.PutID(MessagesEditChatParticipantRankRequestTypeID)
	return e.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (e *MessagesEditChatParticipantRankRequest) EncodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't encode messages.editChatParticipantRank#a00f32b0 as nil")
	}
	if e.Peer == nil {
		return fmt.Errorf("unable to encode messages.editChatParticipantRank#a00f32b0: field peer is nil")
	}
	if err := e.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.editChatParticipantRank#a00f32b0: field peer: %w", err)
	}
	if e.Participant == nil {
		return fmt.Errorf("unable to encode messages.editChatParticipantRank#a00f32b0: field participant is nil")
	}
	if err := e.Participant.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.editChatParticipantRank#a00f32b0: field participant: %w", err)
	}
	b.PutString(e.Rank)
	return nil
}

// Decode implements bin.Decoder.
func (e *MessagesEditChatParticipantRankRequest) Decode(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode messages.editChatParticipantRank#a00f32b0 to nil")
	}
	if err := b.ConsumeID(MessagesEditChatParticipantRankRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.editChatParticipantRank#a00f32b0: %w", err)
	}
	return e.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (e *MessagesEditChatParticipantRankRequest) DecodeBare(b *bin.Buffer) error {
	if e == nil {
		return fmt.Errorf("can't decode messages.editChatParticipantRank#a00f32b0 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.editChatParticipantRank#a00f32b0: field peer: %w", err)
		}
		e.Peer = value
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.editChatParticipantRank#a00f32b0: field participant: %w", err)
		}
		e.Participant = value
	}
	{
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode messages.editChatParticipantRank#a00f32b0: field rank: %w", err)
		}
		e.Rank = value
	}
	return nil
}

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

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

// GetRank returns value of Rank field.
func (e *MessagesEditChatParticipantRankRequest) GetRank() (value string) {
	if e == nil {
		return
	}
	return e.Rank
}

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

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