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

// SetDirectMessagesChatTopicIsMarkedAsUnreadRequest represents TL type `setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913`.
type SetDirectMessagesChatTopicIsMarkedAsUnreadRequest struct {
	// Chat identifier of the channel direct messages chat
	ChatID int64
	// Topic identifier
	TopicID int64
	// New value of is_marked_as_unread
	IsMarkedAsUnread bool
}

// SetDirectMessagesChatTopicIsMarkedAsUnreadRequestTypeID is TL type id of SetDirectMessagesChatTopicIsMarkedAsUnreadRequest.
const SetDirectMessagesChatTopicIsMarkedAsUnreadRequestTypeID = 0x5d8f0913

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

func (s *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.ChatID == 0) {
		return false
	}
	if !(s.TopicID == 0) {
		return false
	}
	if !(s.IsMarkedAsUnread == false) {
		return false
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "setDirectMessagesChatTopicIsMarkedAsUnread",
		ID:   SetDirectMessagesChatTopicIsMarkedAsUnreadRequestTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
		{
			Name:       "TopicID",
			SchemaName: "topic_id",
		},
		{
			Name:       "IsMarkedAsUnread",
			SchemaName: "is_marked_as_unread",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913 as nil")
	}
	b.PutID(SetDirectMessagesChatTopicIsMarkedAsUnreadRequestTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913 as nil")
	}
	b.PutInt53(s.ChatID)
	b.PutInt53(s.TopicID)
	b.PutBool(s.IsMarkedAsUnread)
	return nil
}

// Decode implements bin.Decoder.
func (s *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913 to nil")
	}
	if err := b.ConsumeID(SetDirectMessagesChatTopicIsMarkedAsUnreadRequestTypeID); err != nil {
		return fmt.Errorf("unable to decode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913: field topic_id: %w", err)
		}
		s.TopicID = value
	}
	{
		value, err := b.Bool()
		if err != nil {
			return fmt.Errorf("unable to decode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913: field is_marked_as_unread: %w", err)
		}
		s.IsMarkedAsUnread = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913 as nil")
	}
	b.ObjStart()
	b.PutID("setDirectMessagesChatTopicIsMarkedAsUnread")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.FieldStart("topic_id")
	b.PutInt53(s.TopicID)
	b.Comma()
	b.FieldStart("is_marked_as_unread")
	b.PutBool(s.IsMarkedAsUnread)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913 to nil")
	}

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

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

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

// GetIsMarkedAsUnread returns value of IsMarkedAsUnread field.
func (s *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) GetIsMarkedAsUnread() (value bool) {
	if s == nil {
		return
	}
	return s.IsMarkedAsUnread
}

// SetDirectMessagesChatTopicIsMarkedAsUnread invokes method setDirectMessagesChatTopicIsMarkedAsUnread#5d8f0913 returning error if any.
func (c *Client) SetDirectMessagesChatTopicIsMarkedAsUnread(ctx context.Context, request *SetDirectMessagesChatTopicIsMarkedAsUnreadRequest) error {
	var ok Ok

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