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

// SavedMessagesTopicTypeMyNotes represents TL type `savedMessagesTopicTypeMyNotes#b38a41f5`.
type SavedMessagesTopicTypeMyNotes struct {
}

// SavedMessagesTopicTypeMyNotesTypeID is TL type id of SavedMessagesTopicTypeMyNotes.
const SavedMessagesTopicTypeMyNotesTypeID = 0xb38a41f5

// construct implements constructor of SavedMessagesTopicTypeClass.
func (s SavedMessagesTopicTypeMyNotes) construct() SavedMessagesTopicTypeClass { return &s }

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

	_ SavedMessagesTopicTypeClass = &SavedMessagesTopicTypeMyNotes{}
)

func (s *SavedMessagesTopicTypeMyNotes) Zero() bool {
	if s == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SavedMessagesTopicTypeMyNotes) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "savedMessagesTopicTypeMyNotes",
		ID:   SavedMessagesTopicTypeMyNotesTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (s *SavedMessagesTopicTypeMyNotes) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode savedMessagesTopicTypeMyNotes#b38a41f5 as nil")
	}
	b.PutID(SavedMessagesTopicTypeMyNotesTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SavedMessagesTopicTypeMyNotes) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode savedMessagesTopicTypeMyNotes#b38a41f5 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *SavedMessagesTopicTypeMyNotes) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode savedMessagesTopicTypeMyNotes#b38a41f5 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SavedMessagesTopicTypeMyNotes) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode savedMessagesTopicTypeMyNotes#b38a41f5 as nil")
	}
	b.ObjStart()
	b.PutID("savedMessagesTopicTypeMyNotes")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

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

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("savedMessagesTopicTypeMyNotes"); err != nil {
				return fmt.Errorf("unable to decode savedMessagesTopicTypeMyNotes#b38a41f5: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// SavedMessagesTopicTypeAuthorHidden represents TL type `savedMessagesTopicTypeAuthorHidden#703c4195`.
type SavedMessagesTopicTypeAuthorHidden struct {
}

// SavedMessagesTopicTypeAuthorHiddenTypeID is TL type id of SavedMessagesTopicTypeAuthorHidden.
const SavedMessagesTopicTypeAuthorHiddenTypeID = 0x703c4195

// construct implements constructor of SavedMessagesTopicTypeClass.
func (s SavedMessagesTopicTypeAuthorHidden) construct() SavedMessagesTopicTypeClass { return &s }

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

	_ SavedMessagesTopicTypeClass = &SavedMessagesTopicTypeAuthorHidden{}
)

func (s *SavedMessagesTopicTypeAuthorHidden) Zero() bool {
	if s == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SavedMessagesTopicTypeAuthorHidden) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "savedMessagesTopicTypeAuthorHidden",
		ID:   SavedMessagesTopicTypeAuthorHiddenTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{}
	return typ
}

// Encode implements bin.Encoder.
func (s *SavedMessagesTopicTypeAuthorHidden) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode savedMessagesTopicTypeAuthorHidden#703c4195 as nil")
	}
	b.PutID(SavedMessagesTopicTypeAuthorHiddenTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SavedMessagesTopicTypeAuthorHidden) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode savedMessagesTopicTypeAuthorHidden#703c4195 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *SavedMessagesTopicTypeAuthorHidden) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode savedMessagesTopicTypeAuthorHidden#703c4195 to nil")
	}
	if err := b.ConsumeID(SavedMessagesTopicTypeAuthorHiddenTypeID); err != nil {
		return fmt.Errorf("unable to decode savedMessagesTopicTypeAuthorHidden#703c4195: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SavedMessagesTopicTypeAuthorHidden) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode savedMessagesTopicTypeAuthorHidden#703c4195 to nil")
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SavedMessagesTopicTypeAuthorHidden) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode savedMessagesTopicTypeAuthorHidden#703c4195 as nil")
	}
	b.ObjStart()
	b.PutID("savedMessagesTopicTypeAuthorHidden")
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SavedMessagesTopicTypeAuthorHidden) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode savedMessagesTopicTypeAuthorHidden#703c4195 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("savedMessagesTopicTypeAuthorHidden"); err != nil {
				return fmt.Errorf("unable to decode savedMessagesTopicTypeAuthorHidden#703c4195: %w", err)
			}
		default:
			return b.Skip()
		}
		return nil
	})
}

// SavedMessagesTopicTypeSavedFromChat represents TL type `savedMessagesTopicTypeSavedFromChat#993fad58`.
type SavedMessagesTopicTypeSavedFromChat struct {
	// Identifier of the chat
	ChatID int64
}

// SavedMessagesTopicTypeSavedFromChatTypeID is TL type id of SavedMessagesTopicTypeSavedFromChat.
const SavedMessagesTopicTypeSavedFromChatTypeID = 0x993fad58

// construct implements constructor of SavedMessagesTopicTypeClass.
func (s SavedMessagesTopicTypeSavedFromChat) construct() SavedMessagesTopicTypeClass { return &s }

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

	_ SavedMessagesTopicTypeClass = &SavedMessagesTopicTypeSavedFromChat{}
)

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

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func (s *SavedMessagesTopicTypeSavedFromChat) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "savedMessagesTopicTypeSavedFromChat",
		ID:   SavedMessagesTopicTypeSavedFromChatTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "ChatID",
			SchemaName: "chat_id",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *SavedMessagesTopicTypeSavedFromChat) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode savedMessagesTopicTypeSavedFromChat#993fad58 as nil")
	}
	b.PutID(SavedMessagesTopicTypeSavedFromChatTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SavedMessagesTopicTypeSavedFromChat) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode savedMessagesTopicTypeSavedFromChat#993fad58 as nil")
	}
	b.PutInt53(s.ChatID)
	return nil
}

// Decode implements bin.Decoder.
func (s *SavedMessagesTopicTypeSavedFromChat) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode savedMessagesTopicTypeSavedFromChat#993fad58 to nil")
	}
	if err := b.ConsumeID(SavedMessagesTopicTypeSavedFromChatTypeID); err != nil {
		return fmt.Errorf("unable to decode savedMessagesTopicTypeSavedFromChat#993fad58: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SavedMessagesTopicTypeSavedFromChat) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode savedMessagesTopicTypeSavedFromChat#993fad58 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode savedMessagesTopicTypeSavedFromChat#993fad58: field chat_id: %w", err)
		}
		s.ChatID = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (s *SavedMessagesTopicTypeSavedFromChat) EncodeTDLibJSON(b tdjson.Encoder) error {
	if s == nil {
		return fmt.Errorf("can't encode savedMessagesTopicTypeSavedFromChat#993fad58 as nil")
	}
	b.ObjStart()
	b.PutID("savedMessagesTopicTypeSavedFromChat")
	b.Comma()
	b.FieldStart("chat_id")
	b.PutInt53(s.ChatID)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (s *SavedMessagesTopicTypeSavedFromChat) DecodeTDLibJSON(b tdjson.Decoder) error {
	if s == nil {
		return fmt.Errorf("can't decode savedMessagesTopicTypeSavedFromChat#993fad58 to nil")
	}

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

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

// SavedMessagesTopicTypeClassName is schema name of SavedMessagesTopicTypeClass.
const SavedMessagesTopicTypeClassName = "SavedMessagesTopicType"

// SavedMessagesTopicTypeClass represents SavedMessagesTopicType generic type.
//
// Example:
//
//	g, err := tdapi.DecodeSavedMessagesTopicType(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tdapi.SavedMessagesTopicTypeMyNotes: // savedMessagesTopicTypeMyNotes#b38a41f5
//	case *tdapi.SavedMessagesTopicTypeAuthorHidden: // savedMessagesTopicTypeAuthorHidden#703c4195
//	case *tdapi.SavedMessagesTopicTypeSavedFromChat: // savedMessagesTopicTypeSavedFromChat#993fad58
//	default: panic(v)
//	}
type SavedMessagesTopicTypeClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() SavedMessagesTopicTypeClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	EncodeTDLibJSON(b tdjson.Encoder) error
	DecodeTDLibJSON(b tdjson.Decoder) error
}

// DecodeSavedMessagesTopicType implements binary de-serialization for SavedMessagesTopicTypeClass.
func DecodeSavedMessagesTopicType(buf *bin.Buffer) (SavedMessagesTopicTypeClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case SavedMessagesTopicTypeMyNotesTypeID:
		// Decoding savedMessagesTopicTypeMyNotes#b38a41f5.
		v := SavedMessagesTopicTypeMyNotes{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SavedMessagesTopicTypeClass: %w", err)
		}
		return &v, nil
	case SavedMessagesTopicTypeAuthorHiddenTypeID:
		// Decoding savedMessagesTopicTypeAuthorHidden#703c4195.
		v := SavedMessagesTopicTypeAuthorHidden{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SavedMessagesTopicTypeClass: %w", err)
		}
		return &v, nil
	case SavedMessagesTopicTypeSavedFromChatTypeID:
		// Decoding savedMessagesTopicTypeSavedFromChat#993fad58.
		v := SavedMessagesTopicTypeSavedFromChat{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SavedMessagesTopicTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode SavedMessagesTopicTypeClass: %w", bin.NewUnexpectedID(id))
	}
}

// DecodeTDLibJSONSavedMessagesTopicType implements binary de-serialization for SavedMessagesTopicTypeClass.
func DecodeTDLibJSONSavedMessagesTopicType(buf tdjson.Decoder) (SavedMessagesTopicTypeClass, error) {
	id, err := buf.FindTypeID()
	if err != nil {
		return nil, err
	}
	switch id {
	case "savedMessagesTopicTypeMyNotes":
		// Decoding savedMessagesTopicTypeMyNotes#b38a41f5.
		v := SavedMessagesTopicTypeMyNotes{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SavedMessagesTopicTypeClass: %w", err)
		}
		return &v, nil
	case "savedMessagesTopicTypeAuthorHidden":
		// Decoding savedMessagesTopicTypeAuthorHidden#703c4195.
		v := SavedMessagesTopicTypeAuthorHidden{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SavedMessagesTopicTypeClass: %w", err)
		}
		return &v, nil
	case "savedMessagesTopicTypeSavedFromChat":
		// Decoding savedMessagesTopicTypeSavedFromChat#993fad58.
		v := SavedMessagesTopicTypeSavedFromChat{}
		if err := v.DecodeTDLibJSON(buf); err != nil {
			return nil, fmt.Errorf("unable to decode SavedMessagesTopicTypeClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode SavedMessagesTopicTypeClass: %w", tdjson.NewUnexpectedID(id))
	}
}

// SavedMessagesTopicType boxes the SavedMessagesTopicTypeClass providing a helper.
type SavedMessagesTopicTypeBox struct {
	SavedMessagesTopicType SavedMessagesTopicTypeClass
}

// Decode implements bin.Decoder for SavedMessagesTopicTypeBox.
func (b *SavedMessagesTopicTypeBox) Decode(buf *bin.Buffer) error {
	if b == nil {
		return fmt.Errorf("unable to decode SavedMessagesTopicTypeBox to nil")
	}
	v, err := DecodeSavedMessagesTopicType(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.SavedMessagesTopicType = v
	return nil
}

// Encode implements bin.Encode for SavedMessagesTopicTypeBox.
func (b *SavedMessagesTopicTypeBox) Encode(buf *bin.Buffer) error {
	if b == nil || b.SavedMessagesTopicType == nil {
		return fmt.Errorf("unable to encode SavedMessagesTopicTypeClass as nil")
	}
	return b.SavedMessagesTopicType.Encode(buf)
}

// DecodeTDLibJSON implements bin.Decoder for SavedMessagesTopicTypeBox.
func (b *SavedMessagesTopicTypeBox) DecodeTDLibJSON(buf tdjson.Decoder) error {
	if b == nil {
		return fmt.Errorf("unable to decode SavedMessagesTopicTypeBox to nil")
	}
	v, err := DecodeTDLibJSONSavedMessagesTopicType(buf)
	if err != nil {
		return fmt.Errorf("unable to decode boxed value: %w", err)
	}
	b.SavedMessagesTopicType = v
	return nil
}

// EncodeTDLibJSON implements bin.Encode for SavedMessagesTopicTypeBox.
func (b *SavedMessagesTopicTypeBox) EncodeTDLibJSON(buf tdjson.Encoder) error {
	if b == nil || b.SavedMessagesTopicType == nil {
		return fmt.Errorf("unable to encode SavedMessagesTopicTypeClass as nil")
	}
	return b.SavedMessagesTopicType.EncodeTDLibJSON(buf)
}
