// Code generated by gotdgen, DO NOT EDIT.

package tg

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

// MessagesSavedDialogs represents TL type `messages.savedDialogs#f83ae221`.
// Represents some saved message dialogs »¹.
//
// Links:
//  1. https://core.telegram.org/api/saved-messages
//
// See https://core.telegram.org/constructor/messages.savedDialogs for reference.
type MessagesSavedDialogs struct {
	// Saved message dialogs »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/saved-messages
	Dialogs []SavedDialogClass
	// List of last messages from each saved dialog
	Messages []MessageClass
	// Mentioned chats
	Chats []ChatClass
	// Mentioned users
	Users []UserClass
}

// MessagesSavedDialogsTypeID is TL type id of MessagesSavedDialogs.
const MessagesSavedDialogsTypeID = 0xf83ae221

// construct implements constructor of MessagesSavedDialogsClass.
func (s MessagesSavedDialogs) construct() MessagesSavedDialogsClass { return &s }

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

	_ MessagesSavedDialogsClass = &MessagesSavedDialogs{}
)

func (s *MessagesSavedDialogs) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Dialogs == nil) {
		return false
	}
	if !(s.Messages == nil) {
		return false
	}
	if !(s.Chats == nil) {
		return false
	}
	if !(s.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSavedDialogs from given interface.
func (s *MessagesSavedDialogs) FillFrom(from interface {
	GetDialogs() (value []SavedDialogClass)
	GetMessages() (value []MessageClass)
	GetChats() (value []ChatClass)
	GetUsers() (value []UserClass)
}) {
	s.Dialogs = from.GetDialogs()
	s.Messages = from.GetMessages()
	s.Chats = from.GetChats()
	s.Users = from.GetUsers()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesSavedDialogs) TypeName() string {
	return "messages.savedDialogs"
}

// TypeInfo returns info about TL type.
func (s *MessagesSavedDialogs) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.savedDialogs",
		ID:   MessagesSavedDialogsTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Dialogs",
			SchemaName: "dialogs",
		},
		{
			Name:       "Messages",
			SchemaName: "messages",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *MessagesSavedDialogs) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.savedDialogs#f83ae221 as nil")
	}
	b.PutID(MessagesSavedDialogsTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *MessagesSavedDialogs) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.savedDialogs#f83ae221 as nil")
	}
	b.PutVectorHeader(len(s.Dialogs))
	for idx, v := range s.Dialogs {
		if v == nil {
			return fmt.Errorf("unable to encode messages.savedDialogs#f83ae221: field dialogs element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.savedDialogs#f83ae221: field dialogs element with index %d: %w", idx, err)
		}
	}
	b.PutVectorHeader(len(s.Messages))
	for idx, v := range s.Messages {
		if v == nil {
			return fmt.Errorf("unable to encode messages.savedDialogs#f83ae221: field messages element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.savedDialogs#f83ae221: field messages element with index %d: %w", idx, err)
		}
	}
	b.PutVectorHeader(len(s.Chats))
	for idx, v := range s.Chats {
		if v == nil {
			return fmt.Errorf("unable to encode messages.savedDialogs#f83ae221: field chats element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.savedDialogs#f83ae221: field chats element with index %d: %w", idx, err)
		}
	}
	b.PutVectorHeader(len(s.Users))
	for idx, v := range s.Users {
		if v == nil {
			return fmt.Errorf("unable to encode messages.savedDialogs#f83ae221: field users element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.savedDialogs#f83ae221: field users element with index %d: %w", idx, err)
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *MessagesSavedDialogs) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.savedDialogs#f83ae221 to nil")
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogs#f83ae221: field dialogs: %w", err)
		}

		if headerLen > 0 {
			s.Dialogs = make([]SavedDialogClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeSavedDialog(b)
			if err != nil {
				return fmt.Errorf("unable to decode messages.savedDialogs#f83ae221: field dialogs: %w", err)
			}
			s.Dialogs = append(s.Dialogs, value)
		}
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogs#f83ae221: field messages: %w", err)
		}

		if headerLen > 0 {
			s.Messages = make([]MessageClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeMessage(b)
			if err != nil {
				return fmt.Errorf("unable to decode messages.savedDialogs#f83ae221: field messages: %w", err)
			}
			s.Messages = append(s.Messages, value)
		}
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogs#f83ae221: field chats: %w", err)
		}

		if headerLen > 0 {
			s.Chats = make([]ChatClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeChat(b)
			if err != nil {
				return fmt.Errorf("unable to decode messages.savedDialogs#f83ae221: field chats: %w", err)
			}
			s.Chats = append(s.Chats, value)
		}
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogs#f83ae221: field users: %w", err)
		}

		if headerLen > 0 {
			s.Users = make([]UserClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeUser(b)
			if err != nil {
				return fmt.Errorf("unable to decode messages.savedDialogs#f83ae221: field users: %w", err)
			}
			s.Users = append(s.Users, value)
		}
	}
	return nil
}

// GetDialogs returns value of Dialogs field.
func (s *MessagesSavedDialogs) GetDialogs() (value []SavedDialogClass) {
	if s == nil {
		return
	}
	return s.Dialogs
}

// GetMessages returns value of Messages field.
func (s *MessagesSavedDialogs) GetMessages() (value []MessageClass) {
	if s == nil {
		return
	}
	return s.Messages
}

// GetChats returns value of Chats field.
func (s *MessagesSavedDialogs) GetChats() (value []ChatClass) {
	if s == nil {
		return
	}
	return s.Chats
}

// GetUsers returns value of Users field.
func (s *MessagesSavedDialogs) GetUsers() (value []UserClass) {
	if s == nil {
		return
	}
	return s.Users
}

// MapDialogs returns field Dialogs wrapped in SavedDialogClassArray helper.
func (s *MessagesSavedDialogs) MapDialogs() (value SavedDialogClassArray) {
	return SavedDialogClassArray(s.Dialogs)
}

// MapMessages returns field Messages wrapped in MessageClassArray helper.
func (s *MessagesSavedDialogs) MapMessages() (value MessageClassArray) {
	return MessageClassArray(s.Messages)
}

// MapChats returns field Chats wrapped in ChatClassArray helper.
func (s *MessagesSavedDialogs) MapChats() (value ChatClassArray) {
	return ChatClassArray(s.Chats)
}

// MapUsers returns field Users wrapped in UserClassArray helper.
func (s *MessagesSavedDialogs) MapUsers() (value UserClassArray) {
	return UserClassArray(s.Users)
}

// MessagesSavedDialogsSlice represents TL type `messages.savedDialogsSlice#44ba9dd9`.
// Incomplete list of saved message dialogs »¹ with messages and auxiliary data.
//
// Links:
//  1. https://core.telegram.org/api/saved-messages
//
// See https://core.telegram.org/constructor/messages.savedDialogsSlice for reference.
type MessagesSavedDialogsSlice struct {
	// Total number of saved message dialogs
	Count int
	// List of saved message dialogs
	Dialogs []SavedDialogClass
	// List of last messages from dialogs
	Messages []MessageClass
	// Mentioned chats
	Chats []ChatClass
	// Mentioned users
	Users []UserClass
}

// MessagesSavedDialogsSliceTypeID is TL type id of MessagesSavedDialogsSlice.
const MessagesSavedDialogsSliceTypeID = 0x44ba9dd9

// construct implements constructor of MessagesSavedDialogsClass.
func (s MessagesSavedDialogsSlice) construct() MessagesSavedDialogsClass { return &s }

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

	_ MessagesSavedDialogsClass = &MessagesSavedDialogsSlice{}
)

func (s *MessagesSavedDialogsSlice) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Count == 0) {
		return false
	}
	if !(s.Dialogs == nil) {
		return false
	}
	if !(s.Messages == nil) {
		return false
	}
	if !(s.Chats == nil) {
		return false
	}
	if !(s.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSavedDialogsSlice from given interface.
func (s *MessagesSavedDialogsSlice) FillFrom(from interface {
	GetCount() (value int)
	GetDialogs() (value []SavedDialogClass)
	GetMessages() (value []MessageClass)
	GetChats() (value []ChatClass)
	GetUsers() (value []UserClass)
}) {
	s.Count = from.GetCount()
	s.Dialogs = from.GetDialogs()
	s.Messages = from.GetMessages()
	s.Chats = from.GetChats()
	s.Users = from.GetUsers()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesSavedDialogsSlice) TypeName() string {
	return "messages.savedDialogsSlice"
}

// TypeInfo returns info about TL type.
func (s *MessagesSavedDialogsSlice) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.savedDialogsSlice",
		ID:   MessagesSavedDialogsSliceTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "Dialogs",
			SchemaName: "dialogs",
		},
		{
			Name:       "Messages",
			SchemaName: "messages",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *MessagesSavedDialogsSlice) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.savedDialogsSlice#44ba9dd9 as nil")
	}
	b.PutID(MessagesSavedDialogsSliceTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *MessagesSavedDialogsSlice) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.savedDialogsSlice#44ba9dd9 as nil")
	}
	b.PutInt(s.Count)
	b.PutVectorHeader(len(s.Dialogs))
	for idx, v := range s.Dialogs {
		if v == nil {
			return fmt.Errorf("unable to encode messages.savedDialogsSlice#44ba9dd9: field dialogs element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.savedDialogsSlice#44ba9dd9: field dialogs element with index %d: %w", idx, err)
		}
	}
	b.PutVectorHeader(len(s.Messages))
	for idx, v := range s.Messages {
		if v == nil {
			return fmt.Errorf("unable to encode messages.savedDialogsSlice#44ba9dd9: field messages element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.savedDialogsSlice#44ba9dd9: field messages element with index %d: %w", idx, err)
		}
	}
	b.PutVectorHeader(len(s.Chats))
	for idx, v := range s.Chats {
		if v == nil {
			return fmt.Errorf("unable to encode messages.savedDialogsSlice#44ba9dd9: field chats element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.savedDialogsSlice#44ba9dd9: field chats element with index %d: %w", idx, err)
		}
	}
	b.PutVectorHeader(len(s.Users))
	for idx, v := range s.Users {
		if v == nil {
			return fmt.Errorf("unable to encode messages.savedDialogsSlice#44ba9dd9: field users element with index %d is nil", idx)
		}
		if err := v.Encode(b); err != nil {
			return fmt.Errorf("unable to encode messages.savedDialogsSlice#44ba9dd9: field users element with index %d: %w", idx, err)
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *MessagesSavedDialogsSlice) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.savedDialogsSlice#44ba9dd9 to nil")
	}
	if err := b.ConsumeID(MessagesSavedDialogsSliceTypeID); err != nil {
		return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *MessagesSavedDialogsSlice) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.savedDialogsSlice#44ba9dd9 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: field count: %w", err)
		}
		s.Count = value
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: field dialogs: %w", err)
		}

		if headerLen > 0 {
			s.Dialogs = make([]SavedDialogClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeSavedDialog(b)
			if err != nil {
				return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: field dialogs: %w", err)
			}
			s.Dialogs = append(s.Dialogs, value)
		}
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: field messages: %w", err)
		}

		if headerLen > 0 {
			s.Messages = make([]MessageClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeMessage(b)
			if err != nil {
				return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: field messages: %w", err)
			}
			s.Messages = append(s.Messages, value)
		}
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: field chats: %w", err)
		}

		if headerLen > 0 {
			s.Chats = make([]ChatClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeChat(b)
			if err != nil {
				return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: field chats: %w", err)
			}
			s.Chats = append(s.Chats, value)
		}
	}
	{
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: field users: %w", err)
		}

		if headerLen > 0 {
			s.Users = make([]UserClass, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := DecodeUser(b)
			if err != nil {
				return fmt.Errorf("unable to decode messages.savedDialogsSlice#44ba9dd9: field users: %w", err)
			}
			s.Users = append(s.Users, value)
		}
	}
	return nil
}

// GetCount returns value of Count field.
func (s *MessagesSavedDialogsSlice) GetCount() (value int) {
	if s == nil {
		return
	}
	return s.Count
}

// GetDialogs returns value of Dialogs field.
func (s *MessagesSavedDialogsSlice) GetDialogs() (value []SavedDialogClass) {
	if s == nil {
		return
	}
	return s.Dialogs
}

// GetMessages returns value of Messages field.
func (s *MessagesSavedDialogsSlice) GetMessages() (value []MessageClass) {
	if s == nil {
		return
	}
	return s.Messages
}

// GetChats returns value of Chats field.
func (s *MessagesSavedDialogsSlice) GetChats() (value []ChatClass) {
	if s == nil {
		return
	}
	return s.Chats
}

// GetUsers returns value of Users field.
func (s *MessagesSavedDialogsSlice) GetUsers() (value []UserClass) {
	if s == nil {
		return
	}
	return s.Users
}

// MapDialogs returns field Dialogs wrapped in SavedDialogClassArray helper.
func (s *MessagesSavedDialogsSlice) MapDialogs() (value SavedDialogClassArray) {
	return SavedDialogClassArray(s.Dialogs)
}

// MapMessages returns field Messages wrapped in MessageClassArray helper.
func (s *MessagesSavedDialogsSlice) MapMessages() (value MessageClassArray) {
	return MessageClassArray(s.Messages)
}

// MapChats returns field Chats wrapped in ChatClassArray helper.
func (s *MessagesSavedDialogsSlice) MapChats() (value ChatClassArray) {
	return ChatClassArray(s.Chats)
}

// MapUsers returns field Users wrapped in UserClassArray helper.
func (s *MessagesSavedDialogsSlice) MapUsers() (value UserClassArray) {
	return UserClassArray(s.Users)
}

// MessagesSavedDialogsNotModified represents TL type `messages.savedDialogsNotModified#c01f6fe8`.
// The saved dialogs haven't changed
//
// See https://core.telegram.org/constructor/messages.savedDialogsNotModified for reference.
type MessagesSavedDialogsNotModified struct {
	// Number of saved dialogs¹ found server-side by the query
	//
	// Links:
	//  1) https://core.telegram.org/api/saved-messages
	Count int
}

// MessagesSavedDialogsNotModifiedTypeID is TL type id of MessagesSavedDialogsNotModified.
const MessagesSavedDialogsNotModifiedTypeID = 0xc01f6fe8

// construct implements constructor of MessagesSavedDialogsClass.
func (s MessagesSavedDialogsNotModified) construct() MessagesSavedDialogsClass { return &s }

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

	_ MessagesSavedDialogsClass = &MessagesSavedDialogsNotModified{}
)

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

	return true
}

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

// FillFrom fills MessagesSavedDialogsNotModified from given interface.
func (s *MessagesSavedDialogsNotModified) FillFrom(from interface {
	GetCount() (value int)
}) {
	s.Count = from.GetCount()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesSavedDialogsNotModified) TypeName() string {
	return "messages.savedDialogsNotModified"
}

// TypeInfo returns info about TL type.
func (s *MessagesSavedDialogsNotModified) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "messages.savedDialogsNotModified",
		ID:   MessagesSavedDialogsNotModifiedTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "Count",
			SchemaName: "count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (s *MessagesSavedDialogsNotModified) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.savedDialogsNotModified#c01f6fe8 as nil")
	}
	b.PutID(MessagesSavedDialogsNotModifiedTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *MessagesSavedDialogsNotModified) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode messages.savedDialogsNotModified#c01f6fe8 as nil")
	}
	b.PutInt(s.Count)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func (s *MessagesSavedDialogsNotModified) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode messages.savedDialogsNotModified#c01f6fe8 to nil")
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode messages.savedDialogsNotModified#c01f6fe8: field count: %w", err)
		}
		s.Count = value
	}
	return nil
}

// GetCount returns value of Count field.
func (s *MessagesSavedDialogsNotModified) GetCount() (value int) {
	if s == nil {
		return
	}
	return s.Count
}

// MessagesSavedDialogsClassName is schema name of MessagesSavedDialogsClass.
const MessagesSavedDialogsClassName = "messages.SavedDialogs"

// MessagesSavedDialogsClass represents messages.SavedDialogs generic type.
//
// See https://core.telegram.org/type/messages.SavedDialogs for reference.
//
// Example:
//
//	g, err := tg.DecodeMessagesSavedDialogs(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.MessagesSavedDialogs: // messages.savedDialogs#f83ae221
//	case *tg.MessagesSavedDialogsSlice: // messages.savedDialogsSlice#44ba9dd9
//	case *tg.MessagesSavedDialogsNotModified: // messages.savedDialogsNotModified#c01f6fe8
//	default: panic(v)
//	}
type MessagesSavedDialogsClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MessagesSavedDialogsClass

	// 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

	// AsModified tries to map MessagesSavedDialogsClass to ModifiedMessagesSavedDialogs.
	AsModified() (ModifiedMessagesSavedDialogs, bool)
}

// ModifiedMessagesSavedDialogs represents Modified subset of MessagesSavedDialogsClass.
type ModifiedMessagesSavedDialogs interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MessagesSavedDialogsClass

	// 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

	// Saved message dialogs »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/saved-messages
	GetDialogs() (value []SavedDialogClass)

	// List of last messages from each saved dialog
	GetMessages() (value []MessageClass)

	// Mentioned chats
	GetChats() (value []ChatClass)

	// Mentioned users
	GetUsers() (value []UserClass)
}

// AsModified tries to map MessagesSavedDialogs to ModifiedMessagesSavedDialogs.
func (s *MessagesSavedDialogs) AsModified() (ModifiedMessagesSavedDialogs, bool) {
	value, ok := (MessagesSavedDialogsClass(s)).(ModifiedMessagesSavedDialogs)
	return value, ok
}

// AsModified tries to map MessagesSavedDialogsSlice to ModifiedMessagesSavedDialogs.
func (s *MessagesSavedDialogsSlice) AsModified() (ModifiedMessagesSavedDialogs, bool) {
	value, ok := (MessagesSavedDialogsClass(s)).(ModifiedMessagesSavedDialogs)
	return value, ok
}

// AsModified tries to map MessagesSavedDialogsNotModified to ModifiedMessagesSavedDialogs.
func (s *MessagesSavedDialogsNotModified) AsModified() (ModifiedMessagesSavedDialogs, bool) {
	value, ok := (MessagesSavedDialogsClass(s)).(ModifiedMessagesSavedDialogs)
	return value, ok
}

// DecodeMessagesSavedDialogs implements binary de-serialization for MessagesSavedDialogsClass.
func DecodeMessagesSavedDialogs(buf *bin.Buffer) (MessagesSavedDialogsClass, error) {
	id, err := buf.PeekID()
	if err != nil {
		return nil, err
	}
	switch id {
	case MessagesSavedDialogsTypeID:
		// Decoding messages.savedDialogs#f83ae221.
		v := MessagesSavedDialogs{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessagesSavedDialogsClass: %w", err)
		}
		return &v, nil
	case MessagesSavedDialogsSliceTypeID:
		// Decoding messages.savedDialogsSlice#44ba9dd9.
		v := MessagesSavedDialogsSlice{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessagesSavedDialogsClass: %w", err)
		}
		return &v, nil
	case MessagesSavedDialogsNotModifiedTypeID:
		// Decoding messages.savedDialogsNotModified#c01f6fe8.
		v := MessagesSavedDialogsNotModified{}
		if err := v.Decode(buf); err != nil {
			return nil, fmt.Errorf("unable to decode MessagesSavedDialogsClass: %w", err)
		}
		return &v, nil
	default:
		return nil, fmt.Errorf("unable to decode MessagesSavedDialogsClass: %w", bin.NewUnexpectedID(id))
	}
}

// MessagesSavedDialogs boxes the MessagesSavedDialogsClass providing a helper.
type MessagesSavedDialogsBox struct {
	SavedDialogs MessagesSavedDialogsClass
}

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

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