// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

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

// ContactsTopPeersNotModified represents TL type `contacts.topPeersNotModified#de266ef5`.
// Top peer info hasn't changed
//
// See https://core.telegram.org/constructor/contacts.topPeersNotModified for reference.
type ContactsTopPeersNotModified struct {
}

// ContactsTopPeersNotModifiedTypeID is TL type id of ContactsTopPeersNotModified.
const ContactsTopPeersNotModifiedTypeID = 0xde266ef5

// construct implements constructor of ContactsTopPeersClass.
func ( ContactsTopPeersNotModified) () ContactsTopPeersClass { return & }

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

	_ ContactsTopPeersClass = &ContactsTopPeersNotModified{}
)

func ( *ContactsTopPeersNotModified) () bool {
	if  == nil {
		return true
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*ContactsTopPeersNotModified) () string {
	return "contacts.topPeersNotModified"
}

// TypeInfo returns info about TL type.
func ( *ContactsTopPeersNotModified) () tdp.Type {
	 := tdp.Type{
		Name: "contacts.topPeersNotModified",
		ID:   ContactsTopPeersNotModifiedTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{}
	return 
}

// Encode implements bin.Encoder.
func ( *ContactsTopPeersNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.topPeersNotModified#de266ef5 as nil")
	}
	.PutID(ContactsTopPeersNotModifiedTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ContactsTopPeersNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.topPeersNotModified#de266ef5 as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *ContactsTopPeersNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode contacts.topPeersNotModified#de266ef5 to nil")
	}
	if  := .ConsumeID(ContactsTopPeersNotModifiedTypeID);  != nil {
		return fmt.Errorf("unable to decode contacts.topPeersNotModified#de266ef5: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ContactsTopPeersNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode contacts.topPeersNotModified#de266ef5 to nil")
	}
	return nil
}

// ContactsTopPeers represents TL type `contacts.topPeers#70b772a8`.
// Top peers
//
// See https://core.telegram.org/constructor/contacts.topPeers for reference.
type ContactsTopPeers struct {
	// Top peers by top peer category
	Categories []TopPeerCategoryPeers
	// Chats
	Chats []ChatClass
	// Users
	Users []UserClass
}

// ContactsTopPeersTypeID is TL type id of ContactsTopPeers.
const ContactsTopPeersTypeID = 0x70b772a8

// construct implements constructor of ContactsTopPeersClass.
func ( ContactsTopPeers) () ContactsTopPeersClass { return & }

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

	_ ContactsTopPeersClass = &ContactsTopPeers{}
)

func ( *ContactsTopPeers) () bool {
	if  == nil {
		return true
	}
	if !(.Categories == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills ContactsTopPeers from given interface.
func ( *ContactsTopPeers) ( interface {
	() ( []TopPeerCategoryPeers)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Categories = .()
	.Chats = .()
	.Users = .()
}

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

// TypeName returns name of type in TL schema.
func (*ContactsTopPeers) () string {
	return "contacts.topPeers"
}

// TypeInfo returns info about TL type.
func ( *ContactsTopPeers) () tdp.Type {
	 := tdp.Type{
		Name: "contacts.topPeers",
		ID:   ContactsTopPeersTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Categories",
			SchemaName: "categories",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ContactsTopPeers) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.topPeers#70b772a8 as nil")
	}
	.PutID(ContactsTopPeersTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ContactsTopPeers) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.topPeers#70b772a8 as nil")
	}
	.PutVectorHeader(len(.Categories))
	for ,  := range .Categories {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode contacts.topPeers#70b772a8: field categories element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode contacts.topPeers#70b772a8: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode contacts.topPeers#70b772a8: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode contacts.topPeers#70b772a8: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode contacts.topPeers#70b772a8: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *ContactsTopPeers) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode contacts.topPeers#70b772a8 to nil")
	}
	if  := .ConsumeID(ContactsTopPeersTypeID);  != nil {
		return fmt.Errorf("unable to decode contacts.topPeers#70b772a8: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ContactsTopPeers) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode contacts.topPeers#70b772a8 to nil")
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.topPeers#70b772a8: field categories: %w", )
		}

		if  > 0 {
			.Categories = make([]TopPeerCategoryPeers, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  TopPeerCategoryPeers
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode contacts.topPeers#70b772a8: field categories: %w", )
			}
			.Categories = append(.Categories, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.topPeers#70b772a8: field chats: %w", )
		}

		if  > 0 {
			.Chats = make([]ChatClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChat()
			if  != nil {
				return fmt.Errorf("unable to decode contacts.topPeers#70b772a8: field chats: %w", )
			}
			.Chats = append(.Chats, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.topPeers#70b772a8: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode contacts.topPeers#70b772a8: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	return nil
}

// GetCategories returns value of Categories field.
func ( *ContactsTopPeers) () ( []TopPeerCategoryPeers) {
	if  == nil {
		return
	}
	return .Categories
}

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

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

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

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

// ContactsTopPeersDisabled represents TL type `contacts.topPeersDisabled#b52c939d`.
// Top peers disabled
//
// See https://core.telegram.org/constructor/contacts.topPeersDisabled for reference.
type ContactsTopPeersDisabled struct {
}

// ContactsTopPeersDisabledTypeID is TL type id of ContactsTopPeersDisabled.
const ContactsTopPeersDisabledTypeID = 0xb52c939d

// construct implements constructor of ContactsTopPeersClass.
func ( ContactsTopPeersDisabled) () ContactsTopPeersClass { return & }

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

	_ ContactsTopPeersClass = &ContactsTopPeersDisabled{}
)

func ( *ContactsTopPeersDisabled) () bool {
	if  == nil {
		return true
	}

	return true
}

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

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

// TypeName returns name of type in TL schema.
func (*ContactsTopPeersDisabled) () string {
	return "contacts.topPeersDisabled"
}

// TypeInfo returns info about TL type.
func ( *ContactsTopPeersDisabled) () tdp.Type {
	 := tdp.Type{
		Name: "contacts.topPeersDisabled",
		ID:   ContactsTopPeersDisabledTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{}
	return 
}

// Encode implements bin.Encoder.
func ( *ContactsTopPeersDisabled) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.topPeersDisabled#b52c939d as nil")
	}
	.PutID(ContactsTopPeersDisabledTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ContactsTopPeersDisabled) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.topPeersDisabled#b52c939d as nil")
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *ContactsTopPeersDisabled) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode contacts.topPeersDisabled#b52c939d to nil")
	}
	if  := .ConsumeID(ContactsTopPeersDisabledTypeID);  != nil {
		return fmt.Errorf("unable to decode contacts.topPeersDisabled#b52c939d: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ContactsTopPeersDisabled) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode contacts.topPeersDisabled#b52c939d to nil")
	}
	return nil
}

// ContactsTopPeersClassName is schema name of ContactsTopPeersClass.
const ContactsTopPeersClassName = "contacts.TopPeers"

// ContactsTopPeersClass represents contacts.TopPeers generic type.
//
// See https://core.telegram.org/type/contacts.TopPeers for reference.
//
// Example:
//
//	g, err := tg.DecodeContactsTopPeers(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.ContactsTopPeersNotModified: // contacts.topPeersNotModified#de266ef5
//	case *tg.ContactsTopPeers: // contacts.topPeers#70b772a8
//	case *tg.ContactsTopPeersDisabled: // contacts.topPeersDisabled#b52c939d
//	default: panic(v)
//	}
type ContactsTopPeersClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ContactsTopPeersClass

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

// DecodeContactsTopPeers implements binary de-serialization for ContactsTopPeersClass.
func ( *bin.Buffer) (ContactsTopPeersClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case ContactsTopPeersNotModifiedTypeID:
		// Decoding contacts.topPeersNotModified#de266ef5.
		 := ContactsTopPeersNotModified{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ContactsTopPeersClass: %w", )
		}
		return &, nil
	case ContactsTopPeersTypeID:
		// Decoding contacts.topPeers#70b772a8.
		 := ContactsTopPeers{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ContactsTopPeersClass: %w", )
		}
		return &, nil
	case ContactsTopPeersDisabledTypeID:
		// Decoding contacts.topPeersDisabled#b52c939d.
		 := ContactsTopPeersDisabled{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ContactsTopPeersClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode ContactsTopPeersClass: %w", bin.NewUnexpectedID())
	}
}

// ContactsTopPeers boxes the ContactsTopPeersClass providing a helper.
type ContactsTopPeersBox struct {
	TopPeers ContactsTopPeersClass
}

// Decode implements bin.Decoder for ContactsTopPeersBox.
func ( *ContactsTopPeersBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode ContactsTopPeersBox to nil")
	}
	,  := DecodeContactsTopPeers()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.TopPeers = 
	return nil
}

// Encode implements bin.Encode for ContactsTopPeersBox.
func ( *ContactsTopPeersBox) ( *bin.Buffer) error {
	if  == nil || .TopPeers == nil {
		return fmt.Errorf("unable to encode ContactsTopPeersClass as nil")
	}
	return .TopPeers.Encode()
}