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

// ReadAllMessageThreadReactionsRequest represents TL type `readAllMessageThreadReactions#d0bc273e`.
type ReadAllMessageThreadReactionsRequest struct {
	// Chat identifier
	ChatID int64
	// Message thread identifier in which reactions are marked as read
	MessageThreadID int64
}

// ReadAllMessageThreadReactionsRequestTypeID is TL type id of ReadAllMessageThreadReactionsRequest.
const ReadAllMessageThreadReactionsRequestTypeID = 0xd0bc273e

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

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (r *ReadAllMessageThreadReactionsRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "readAllMessageThreadReactions",
		ID:   ReadAllMessageThreadReactionsRequestTypeID,
	}
	if r == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "MessageThreadID",
			SchemaName: "message_thread_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (r *ReadAllMessageThreadReactionsRequest) Encode(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode readAllMessageThreadReactions#d0bc273e as nil")
	}
	b.PutID(ReadAllMessageThreadReactionsRequestTypeID)
	return r.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (r *ReadAllMessageThreadReactionsRequest) EncodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't encode readAllMessageThreadReactions#d0bc273e as nil")
	}
	b.PutInt53(r.ChatID)
	b.PutInt53(r.MessageThreadID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (r *ReadAllMessageThreadReactionsRequest) DecodeBare(b *bin.Buffer) error {
	if r == nil {
		return fmt.Errorf("can't decode readAllMessageThreadReactions#d0bc273e to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode readAllMessageThreadReactions#d0bc273e: field chat_id: %w", err)
		}
		r.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode readAllMessageThreadReactions#d0bc273e: field message_thread_id: %w", err)
		}
		r.MessageThreadID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (r *ReadAllMessageThreadReactionsRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if r == nil {
		return fmt.Errorf("can't encode readAllMessageThreadReactions#d0bc273e as nil")
	}
	b.ObjStart()
	b.PutID("readAllMessageThreadReactions")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(r.ChatID)
	b.Comma()
	b.FieldStart("message_thread_id")
	b.PutInt53(r.MessageThreadID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

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

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

// GetMessageThreadID returns value of MessageThreadID field.
func (r *ReadAllMessageThreadReactionsRequest) GetMessageThreadID() (value int64) {
	if r == nil {
		return
	}
	return r.MessageThreadID
}

// ReadAllMessageThreadReactions invokes method readAllMessageThreadReactions#d0bc273e returning error if any.
func (c *Client) ReadAllMessageThreadReactions(ctx context.Context, request *ReadAllMessageThreadReactionsRequest) error {
	var ok Ok

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