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

// ReadAllDirectMessagesChatTopicReactionsRequest represents TL type `readAllDirectMessagesChatTopicReactions#44d2cc46`.
type ReadAllDirectMessagesChatTopicReactionsRequest struct {
	// Identifier of the chat
	ChatID int64
	// Topic identifier
	TopicID int64
}

// ReadAllDirectMessagesChatTopicReactionsRequestTypeID is TL type id of ReadAllDirectMessagesChatTopicReactionsRequest.
const ReadAllDirectMessagesChatTopicReactionsRequestTypeID = 0x44d2cc46

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *ReadAllDirectMessagesChatTopicReactionsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "readAllDirectMessagesChatTopicReactions",
		ID:   ReadAllDirectMessagesChatTopicReactionsRequestTypeID,
	}
	if r == 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 (r *ReadAllDirectMessagesChatTopicReactionsRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode readAllDirectMessagesChatTopicReactions#44d2cc46 as nil")
	}
	b.PutID(ReadAllDirectMessagesChatTopicReactionsRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ReadAllDirectMessagesChatTopicReactionsRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode readAllDirectMessagesChatTopicReactions#44d2cc46 as nil")
	}
	b.PutInt53(r.ChatID)
	b.PutInt53(r.TopicID)
	return nil
}

// Decode implements bin.Decoder.
func (r *ReadAllDirectMessagesChatTopicReactionsRequest) Decode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode readAllDirectMessagesChatTopicReactions#44d2cc46 to nil")
	}
	if err := b.ConsumeID(ReadAllDirectMessagesChatTopicReactionsRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode readAllDirectMessagesChatTopicReactions#44d2cc46: %w", err)
	}
	return r.DecodeBare(b)
}

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

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *ReadAllDirectMessagesChatTopicReactionsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode readAllDirectMessagesChatTopicReactions#44d2cc46 as nil")
	}
	b.ObjStart()
	b.PutID("readAllDirectMessagesChatTopicReactions")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(r.ChatID)
	b.Comma()
	b.FieldStart("topic_id")
	b.PutInt53(r.TopicID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (r *ReadAllDirectMessagesChatTopicReactionsRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if r == nil {
		return fmt.Errorf("can't decode readAllDirectMessagesChatTopicReactions#44d2cc46 to nil")
	}

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

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

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

// ReadAllDirectMessagesChatTopicReactions invokes method readAllDirectMessagesChatTopicReactions#44d2cc46 returning error if any.
func (c *Client) ReadAllDirectMessagesChatTopicReactions(ctx context.Context, request *ReadAllDirectMessagesChatTopicReactionsRequest) error {
	var ok Ok

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