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

// MessagesUpdatePinnedForumTopicRequest represents TL type `messages.updatePinnedForumTopic#175df251`.
//
// See https://core.telegram.org/method/messages.updatePinnedForumTopic for reference.
type MessagesUpdatePinnedForumTopicRequest struct {
	// Peer field of MessagesUpdatePinnedForumTopicRequest.
	Peer InputPeerClass
	// TopicID field of MessagesUpdatePinnedForumTopicRequest.
	TopicID int
	// Pinned field of MessagesUpdatePinnedForumTopicRequest.
	Pinned bool
}

// MessagesUpdatePinnedForumTopicRequestTypeID is TL type id of MessagesUpdatePinnedForumTopicRequest.
const MessagesUpdatePinnedForumTopicRequestTypeID = 0x175df251

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

func (u *MessagesUpdatePinnedForumTopicRequest) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.Peer == nil) {
		return false
	}
	if !(u.TopicID == 0) {
		return false
	}
	if !(u.Pinned == false) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesUpdatePinnedForumTopicRequest from given interface.
func (u *MessagesUpdatePinnedForumTopicRequest) FillFrom(from interface {
	GetPeer() (value InputPeerClass)
	GetTopicID() (value int)
	GetPinned() (value bool)
}) {
	u.Peer = from.GetPeer()
	u.TopicID = from.GetTopicID()
	u.Pinned = from.GetPinned()
}

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

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

// TypeInfo returns info about TL type.
func (u *MessagesUpdatePinnedForumTopicRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.updatePinnedForumTopic",
		ID:   MessagesUpdatePinnedForumTopicRequestTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "TopicID",
			SchemaName: "topic_id",
		},
		{
			Name:       "Pinned",
			SchemaName: "pinned",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *MessagesUpdatePinnedForumTopicRequest) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode messages.updatePinnedForumTopic#175df251 as nil")
	}
	b.PutID(MessagesUpdatePinnedForumTopicRequestTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *MessagesUpdatePinnedForumTopicRequest) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode messages.updatePinnedForumTopic#175df251 as nil")
	}
	if u.Peer == nil {
		return fmt.Errorf("unable to encode messages.updatePinnedForumTopic#175df251: field peer is nil")
	}
	if err := u.Peer.Encode(b); err != nil {
		return fmt.Errorf("unable to encode messages.updatePinnedForumTopic#175df251: field peer: %w", err)
	}
	b.PutInt(u.TopicID)
	b.PutBool(u.Pinned)
	return nil
}

// Decode implements bin.Decoder.
func (u *MessagesUpdatePinnedForumTopicRequest) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode messages.updatePinnedForumTopic#175df251 to nil")
	}
	if err := b.ConsumeID(MessagesUpdatePinnedForumTopicRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.updatePinnedForumTopic#175df251: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *MessagesUpdatePinnedForumTopicRequest) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode messages.updatePinnedForumTopic#175df251 to nil")
	}
	{
		value, err := DecodeInputPeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode messages.updatePinnedForumTopic#175df251: field peer: %w", err)
		}
		u.Peer = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.updatePinnedForumTopic#175df251: field topic_id: %w", err)
		}
		u.TopicID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode messages.updatePinnedForumTopic#175df251: field pinned: %w", err)
		}
		u.Pinned = value
	}
	return nil
}

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

// GetTopicID returns value of TopicID field.
func (u *MessagesUpdatePinnedForumTopicRequest) GetTopicID() (value int) {
	if u == nil {
		return
	}
	return u.TopicID
}

// GetPinned returns value of Pinned field.
func (u *MessagesUpdatePinnedForumTopicRequest) GetPinned() (value bool) {
	if u == nil {
		return
	}
	return u.Pinned
}

// MessagesUpdatePinnedForumTopic invokes method messages.updatePinnedForumTopic#175df251 returning error if any.
//
// See https://core.telegram.org/method/messages.updatePinnedForumTopic for reference.
func (c *Client) MessagesUpdatePinnedForumTopic(ctx context.Context, request *MessagesUpdatePinnedForumTopicRequest) (UpdatesClass, error) {
	var result UpdatesBox

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