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

// ContactsContactsNotModified represents TL type `contacts.contactsNotModified#b74ba9d2`.
// Contact list on the server is the same as the list on the client.
//
// See https://core.telegram.org/constructor/contacts.contactsNotModified for reference.
type ContactsContactsNotModified struct {
}

// ContactsContactsNotModifiedTypeID is TL type id of ContactsContactsNotModified.
const ContactsContactsNotModifiedTypeID = 0xb74ba9d2

// construct implements constructor of ContactsContactsClass.
func ( ContactsContactsNotModified) () ContactsContactsClass { return & }

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

	_ ContactsContactsClass = &ContactsContactsNotModified{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func ( *ContactsContactsNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.contactsNotModified#b74ba9d2 as nil")
	}
	.PutID(ContactsContactsNotModifiedTypeID)
	return .EncodeBare()
}

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

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

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

// ContactsContacts represents TL type `contacts.contacts#eae87e42`.
// The current user's contact list and info on users.
//
// See https://core.telegram.org/constructor/contacts.contacts for reference.
type ContactsContacts struct {
	// Contact list
	Contacts []Contact
	// Number of contacts that were saved successfully
	SavedCount int
	// User list
	Users []UserClass
}

// ContactsContactsTypeID is TL type id of ContactsContacts.
const ContactsContactsTypeID = 0xeae87e42

// construct implements constructor of ContactsContactsClass.
func ( ContactsContacts) () ContactsContactsClass { return & }

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

	_ ContactsContactsClass = &ContactsContacts{}
)

func ( *ContactsContacts) () bool {
	if  == nil {
		return true
	}
	if !(.Contacts == nil) {
		return false
	}
	if !(.SavedCount == 0) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills ContactsContacts from given interface.
func ( *ContactsContacts) ( interface {
	() ( []Contact)
	() ( int)
	() ( []UserClass)
}) {
	.Contacts = .()
	.SavedCount = .()
	.Users = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *ContactsContacts) () tdp.Type {
	 := tdp.Type{
		Name: "contacts.contacts",
		ID:   ContactsContactsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Contacts",
			SchemaName: "contacts",
		},
		{
			Name:       "SavedCount",
			SchemaName: "saved_count",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

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

// EncodeBare implements bin.BareEncoder.
func ( *ContactsContacts) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.contacts#eae87e42 as nil")
	}
	.PutVectorHeader(len(.Contacts))
	for ,  := range .Contacts {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode contacts.contacts#eae87e42: field contacts element with index %d: %w", , )
		}
	}
	.PutInt(.SavedCount)
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode contacts.contacts#eae87e42: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode contacts.contacts#eae87e42: field users element with index %d: %w", , )
		}
	}
	return nil
}

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

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

		if  > 0 {
			.Contacts = make([]Contact, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  Contact
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode contacts.contacts#eae87e42: field contacts: %w", )
			}
			.Contacts = append(.Contacts, )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.contacts#eae87e42: field saved_count: %w", )
		}
		.SavedCount = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.contacts#eae87e42: field users: %w", )
		}

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

// GetContacts returns value of Contacts field.
func ( *ContactsContacts) () ( []Contact) {
	if  == nil {
		return
	}
	return .Contacts
}

// GetSavedCount returns value of SavedCount field.
func ( *ContactsContacts) () ( int) {
	if  == nil {
		return
	}
	return .SavedCount
}

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

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

// ContactsContactsClassName is schema name of ContactsContactsClass.
const ContactsContactsClassName = "contacts.Contacts"

// ContactsContactsClass represents contacts.Contacts generic type.
//
// See https://core.telegram.org/type/contacts.Contacts for reference.
//
// Example:
//
//	g, err := tg.DecodeContactsContacts(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.ContactsContactsNotModified: // contacts.contactsNotModified#b74ba9d2
//	case *tg.ContactsContacts: // contacts.contacts#eae87e42
//	default: panic(v)
//	}
type ContactsContactsClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ContactsContactsClass

	// 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 ContactsContactsClass to ContactsContacts.
	AsModified() (*ContactsContacts, bool)
}

// AsModified tries to map ContactsContactsNotModified to ContactsContacts.
func ( *ContactsContactsNotModified) () (*ContactsContacts, bool) {
	return nil, false
}

// AsModified tries to map ContactsContacts to ContactsContacts.
func ( *ContactsContacts) () (*ContactsContacts, bool) {
	return , true
}

// DecodeContactsContacts implements binary de-serialization for ContactsContactsClass.
func ( *bin.Buffer) (ContactsContactsClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case ContactsContactsNotModifiedTypeID:
		// Decoding contacts.contactsNotModified#b74ba9d2.
		 := ContactsContactsNotModified{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ContactsContactsClass: %w", )
		}
		return &, nil
	case ContactsContactsTypeID:
		// Decoding contacts.contacts#eae87e42.
		 := ContactsContacts{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ContactsContactsClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode ContactsContactsClass: %w", bin.NewUnexpectedID())
	}
}

// ContactsContacts boxes the ContactsContactsClass providing a helper.
type ContactsContactsBox struct {
	Contacts ContactsContactsClass
}

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

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