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

// UnpinAllDirectMessagesChatTopicMessagesRequest represents TL type `unpinAllDirectMessagesChatTopicMessages#55845bc`.
type UnpinAllDirectMessagesChatTopicMessagesRequest struct {
	// Identifier of the chat
	ChatID int64
	// Topic identifier
	TopicID int64
}

// UnpinAllDirectMessagesChatTopicMessagesRequestTypeID is TL type id of UnpinAllDirectMessagesChatTopicMessagesRequest.
const UnpinAllDirectMessagesChatTopicMessagesRequestTypeID = 0x55845bc

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

func (u *UnpinAllDirectMessagesChatTopicMessagesRequest) Zero() bool {
	if u == nil {
		return true
	}
	if !(u.ChatID == 0) {
		return false
	}
	if !(u.TopicID == 0) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (u *UnpinAllDirectMessagesChatTopicMessagesRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "unpinAllDirectMessagesChatTopicMessages",
		ID:   UnpinAllDirectMessagesChatTopicMessagesRequestTypeID,
	}
	if u == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "TopicID",
			SchemaName: "topic_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (u *UnpinAllDirectMessagesChatTopicMessagesRequest) Encode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode unpinAllDirectMessagesChatTopicMessages#55845bc as nil")
	}
	b.PutID(UnpinAllDirectMessagesChatTopicMessagesRequestTypeID)
	return u.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (u *UnpinAllDirectMessagesChatTopicMessagesRequest) EncodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't encode unpinAllDirectMessagesChatTopicMessages#55845bc as nil")
	}
	b.PutInt53(u.ChatID)
	b.PutInt53(u.TopicID)
	return nil
}

// Decode implements bin.Decoder.
func (u *UnpinAllDirectMessagesChatTopicMessagesRequest) Decode(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode unpinAllDirectMessagesChatTopicMessages#55845bc to nil")
	}
	if err := b.ConsumeID(UnpinAllDirectMessagesChatTopicMessagesRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode unpinAllDirectMessagesChatTopicMessages#55845bc: %w", err)
	}
	return u.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (u *UnpinAllDirectMessagesChatTopicMessagesRequest) DecodeBare(b *bin.Buffer) error {
	if u == nil {
		return fmt.Errorf("can't decode unpinAllDirectMessagesChatTopicMessages#55845bc to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode unpinAllDirectMessagesChatTopicMessages#55845bc: field chat_id: %w", err)
		}
		u.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode unpinAllDirectMessagesChatTopicMessages#55845bc: field topic_id: %w", err)
		}
		u.TopicID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (u *UnpinAllDirectMessagesChatTopicMessagesRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if u == nil {
		return fmt.Errorf("can't encode unpinAllDirectMessagesChatTopicMessages#55845bc as nil")
	}
	b.ObjStart()
	b.PutID("unpinAllDirectMessagesChatTopicMessages")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(u.ChatID)
	b.Comma()
	b.FieldStart("topic_id")
	b.PutInt53(u.TopicID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (u *UnpinAllDirectMessagesChatTopicMessagesRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if u == nil {
		return fmt.Errorf("can't decode unpinAllDirectMessagesChatTopicMessages#55845bc to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("unpinAllDirectMessagesChatTopicMessages"); err != nil {
				return fmt.Errorf("unable to decode unpinAllDirectMessagesChatTopicMessages#55845bc: %w", err)
			}
		case "chat_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode unpinAllDirectMessagesChatTopicMessages#55845bc: field chat_id: %w", err)
			}
			u.ChatID = value
		case "topic_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode unpinAllDirectMessagesChatTopicMessages#55845bc: field topic_id: %w", err)
			}
			u.TopicID = value
		default:
			return b.Skip()
		}
		return nil
	})
}

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

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

// UnpinAllDirectMessagesChatTopicMessages invokes method unpinAllDirectMessagesChatTopicMessages#55845bc returning error if any.
func (c *Client) UnpinAllDirectMessagesChatTopicMessages(ctx context.Context, request *UnpinAllDirectMessagesChatTopicMessagesRequest) error {
	var ok Ok

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