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

// MessagesChats represents TL type `messages.chats#64ff9fd5`.
// List of chats with auxiliary data.
//
// See https://core.telegram.org/constructor/messages.chats for reference.
type MessagesChats struct {
	// List of chats
	Chats []ChatClass
}

// MessagesChatsTypeID is TL type id of MessagesChats.
const MessagesChatsTypeID = 0x64ff9fd5

// construct implements constructor of MessagesChatsClass.
func ( MessagesChats) () MessagesChatsClass { return & }

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

	_ MessagesChatsClass = &MessagesChats{}
)

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

	return true
}

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

// FillFrom fills MessagesChats from given interface.
func ( *MessagesChats) ( interface {
	() ( []ChatClass)
}) {
	.Chats = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesChats) () tdp.Type {
	 := tdp.Type{
		Name: "messages.chats",
		ID:   MessagesChatsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *MessagesChats) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.chats#64ff9fd5 as nil")
	}
	.PutID(MessagesChatsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesChats) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.chats#64ff9fd5 as nil")
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode messages.chats#64ff9fd5: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.chats#64ff9fd5: field chats element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *MessagesChats) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.chats#64ff9fd5 to nil")
	}
	if  := .ConsumeID(MessagesChatsTypeID);  != nil {
		return fmt.Errorf("unable to decode messages.chats#64ff9fd5: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MessagesChats) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.chats#64ff9fd5 to nil")
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.chats#64ff9fd5: field chats: %w", )
		}

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

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

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

// MessagesChatsSlice represents TL type `messages.chatsSlice#9cd81144`.
// Partial list of chats, more would have to be fetched with pagination¹
//
// Links:
//  1. https://core.telegram.org/api/offsets
//
// See https://core.telegram.org/constructor/messages.chatsSlice for reference.
type MessagesChatsSlice struct {
	// Total number of results that were found server-side (not all are included in chats)
	Count int
	// Chats
	Chats []ChatClass
}

// MessagesChatsSliceTypeID is TL type id of MessagesChatsSlice.
const MessagesChatsSliceTypeID = 0x9cd81144

// construct implements constructor of MessagesChatsClass.
func ( MessagesChatsSlice) () MessagesChatsClass { return & }

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

	_ MessagesChatsClass = &MessagesChatsSlice{}
)

func ( *MessagesChatsSlice) () bool {
	if  == nil {
		return true
	}
	if !(.Count == 0) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesChatsSlice from given interface.
func ( *MessagesChatsSlice) ( interface {
	() ( int)
	() ( []ChatClass)
}) {
	.Count = .()
	.Chats = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesChatsSlice) () tdp.Type {
	 := tdp.Type{
		Name: "messages.chatsSlice",
		ID:   MessagesChatsSliceTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *MessagesChatsSlice) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.chatsSlice#9cd81144 as nil")
	}
	.PutID(MessagesChatsSliceTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesChatsSlice) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.chatsSlice#9cd81144 as nil")
	}
	.PutInt(.Count)
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode messages.chatsSlice#9cd81144: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.chatsSlice#9cd81144: field chats element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *MessagesChatsSlice) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.chatsSlice#9cd81144 to nil")
	}
	if  := .ConsumeID(MessagesChatsSliceTypeID);  != nil {
		return fmt.Errorf("unable to decode messages.chatsSlice#9cd81144: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MessagesChatsSlice) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.chatsSlice#9cd81144 to nil")
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.chatsSlice#9cd81144: field count: %w", )
		}
		.Count = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.chatsSlice#9cd81144: field chats: %w", )
		}

		if  > 0 {
			.Chats = make([]ChatClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChat()
			if  != nil {
				return fmt.Errorf("unable to decode messages.chatsSlice#9cd81144: field chats: %w", )
			}
			.Chats = append(.Chats, )
		}
	}
	return nil
}

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

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

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

// MessagesChatsClassName is schema name of MessagesChatsClass.
const MessagesChatsClassName = "messages.Chats"

// MessagesChatsClass represents messages.Chats generic type.
//
// See https://core.telegram.org/type/messages.Chats for reference.
//
// Example:
//
//	g, err := tg.DecodeMessagesChats(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.MessagesChats: // messages.chats#64ff9fd5
//	case *tg.MessagesChatsSlice: // messages.chatsSlice#9cd81144
//	default: panic(v)
//	}
type MessagesChatsClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MessagesChatsClass

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

	// List of chats
	GetChats() (value []ChatClass)
	// List of chats
	MapChats() (value ChatClassArray)
}

// DecodeMessagesChats implements binary de-serialization for MessagesChatsClass.
func ( *bin.Buffer) (MessagesChatsClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case MessagesChatsTypeID:
		// Decoding messages.chats#64ff9fd5.
		 := MessagesChats{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode MessagesChatsClass: %w", )
		}
		return &, nil
	case MessagesChatsSliceTypeID:
		// Decoding messages.chatsSlice#9cd81144.
		 := MessagesChatsSlice{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode MessagesChatsClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode MessagesChatsClass: %w", bin.NewUnexpectedID())
	}
}

// MessagesChats boxes the MessagesChatsClass providing a helper.
type MessagesChatsBox struct {
	Chats MessagesChatsClass
}

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

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