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

// ContactsFound represents TL type `contacts.found#b3134d9d`.
// Users found by name substring and auxiliary data.
//
// See https://core.telegram.org/constructor/contacts.found for reference.
type ContactsFound struct {
	// Personalized results
	MyResults []PeerClass
	// List of found user identifiers
	Results []PeerClass
	// Found chats
	Chats []ChatClass
	// List of users
	Users []UserClass
}

// ContactsFoundTypeID is TL type id of ContactsFound.
const ContactsFoundTypeID = 0xb3134d9d

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

func ( *ContactsFound) () bool {
	if  == nil {
		return true
	}
	if !(.MyResults == nil) {
		return false
	}
	if !(.Results == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills ContactsFound from given interface.
func ( *ContactsFound) ( interface {
	() ( []PeerClass)
	() ( []PeerClass)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.MyResults = .()
	.Results = .()
	.Chats = .()
	.Users = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *ContactsFound) () tdp.Type {
	 := tdp.Type{
		Name: "contacts.found",
		ID:   ContactsFoundTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "MyResults",
			SchemaName: "my_results",
		},
		{
			Name:       "Results",
			SchemaName: "results",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ContactsFound) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.found#b3134d9d as nil")
	}
	.PutID(ContactsFoundTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ContactsFound) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.found#b3134d9d as nil")
	}
	.PutVectorHeader(len(.MyResults))
	for ,  := range .MyResults {
		if  == nil {
			return fmt.Errorf("unable to encode contacts.found#b3134d9d: field my_results element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode contacts.found#b3134d9d: field my_results element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Results))
	for ,  := range .Results {
		if  == nil {
			return fmt.Errorf("unable to encode contacts.found#b3134d9d: field results element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode contacts.found#b3134d9d: field results element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode contacts.found#b3134d9d: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode contacts.found#b3134d9d: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode contacts.found#b3134d9d: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode contacts.found#b3134d9d: field users element with index %d: %w", , )
		}
	}
	return nil
}

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

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

		if  > 0 {
			.MyResults = make([]PeerClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePeer()
			if  != nil {
				return fmt.Errorf("unable to decode contacts.found#b3134d9d: field my_results: %w", )
			}
			.MyResults = append(.MyResults, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.found#b3134d9d: field results: %w", )
		}

		if  > 0 {
			.Results = make([]PeerClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePeer()
			if  != nil {
				return fmt.Errorf("unable to decode contacts.found#b3134d9d: field results: %w", )
			}
			.Results = append(.Results, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.found#b3134d9d: field chats: %w", )
		}

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

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

// GetMyResults returns value of MyResults field.
func ( *ContactsFound) () ( []PeerClass) {
	if  == nil {
		return
	}
	return .MyResults
}

// GetResults returns value of Results field.
func ( *ContactsFound) () ( []PeerClass) {
	if  == nil {
		return
	}
	return .Results
}

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

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

// MapMyResults returns field MyResults wrapped in PeerClassArray helper.
func ( *ContactsFound) () ( PeerClassArray) {
	return PeerClassArray(.MyResults)
}

// MapResults returns field Results wrapped in PeerClassArray helper.
func ( *ContactsFound) () ( PeerClassArray) {
	return PeerClassArray(.Results)
}

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

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