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

// ContactsGetTopPeersRequest represents TL type `contacts.getTopPeers#973478b6`.
// Get most used peers
//
// See https://core.telegram.org/method/contacts.getTopPeers for reference.
type ContactsGetTopPeersRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Users we've chatted most frequently with
	Correspondents bool
	// Most used bots
	BotsPm bool
	// Most used inline bots
	BotsInline bool
	// Most frequently called users
	PhoneCalls bool
	// Users to which the users often forwards messages to
	ForwardUsers bool
	// Chats to which the users often forwards messages to
	ForwardChats bool
	// Often-opened groups and supergroups
	Groups bool
	// Most frequently visited channels
	Channels bool
	// Offset for pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Offset int
	// Maximum number of results to return, see pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Limit int
	// Hash for pagination, for more info click here¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets#hash-generation
	Hash int64
}

// ContactsGetTopPeersRequestTypeID is TL type id of ContactsGetTopPeersRequest.
const ContactsGetTopPeersRequestTypeID = 0x973478b6

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

func ( *ContactsGetTopPeersRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Correspondents == false) {
		return false
	}
	if !(.BotsPm == false) {
		return false
	}
	if !(.BotsInline == false) {
		return false
	}
	if !(.PhoneCalls == false) {
		return false
	}
	if !(.ForwardUsers == false) {
		return false
	}
	if !(.ForwardChats == false) {
		return false
	}
	if !(.Groups == false) {
		return false
	}
	if !(.Channels == false) {
		return false
	}
	if !(.Offset == 0) {
		return false
	}
	if !(.Limit == 0) {
		return false
	}
	if !(.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills ContactsGetTopPeersRequest from given interface.
func ( *ContactsGetTopPeersRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( int)
	() ( int)
	() ( int64)
}) {
	.Correspondents = .()
	.BotsPm = .()
	.BotsInline = .()
	.PhoneCalls = .()
	.ForwardUsers = .()
	.ForwardChats = .()
	.Groups = .()
	.Channels = .()
	.Offset = .()
	.Limit = .()
	.Hash = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *ContactsGetTopPeersRequest) () tdp.Type {
	 := tdp.Type{
		Name: "contacts.getTopPeers",
		ID:   ContactsGetTopPeersRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Correspondents",
			SchemaName: "correspondents",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "BotsPm",
			SchemaName: "bots_pm",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "BotsInline",
			SchemaName: "bots_inline",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "PhoneCalls",
			SchemaName: "phone_calls",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "ForwardUsers",
			SchemaName: "forward_users",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "ForwardChats",
			SchemaName: "forward_chats",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Groups",
			SchemaName: "groups",
			Null:       !.Flags.Has(10),
		},
		{
			Name:       "Channels",
			SchemaName: "channels",
			Null:       !.Flags.Has(15),
		},
		{
			Name:       "Offset",
			SchemaName: "offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *ContactsGetTopPeersRequest) () {
	if !(.Correspondents == false) {
		.Flags.Set(0)
	}
	if !(.BotsPm == false) {
		.Flags.Set(1)
	}
	if !(.BotsInline == false) {
		.Flags.Set(2)
	}
	if !(.PhoneCalls == false) {
		.Flags.Set(3)
	}
	if !(.ForwardUsers == false) {
		.Flags.Set(4)
	}
	if !(.ForwardChats == false) {
		.Flags.Set(5)
	}
	if !(.Groups == false) {
		.Flags.Set(10)
	}
	if !(.Channels == false) {
		.Flags.Set(15)
	}
}

// Encode implements bin.Encoder.
func ( *ContactsGetTopPeersRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.getTopPeers#973478b6 as nil")
	}
	.PutID(ContactsGetTopPeersRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ContactsGetTopPeersRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.getTopPeers#973478b6 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode contacts.getTopPeers#973478b6: field flags: %w", )
	}
	.PutInt(.Offset)
	.PutInt(.Limit)
	.PutLong(.Hash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *ContactsGetTopPeersRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode contacts.getTopPeers#973478b6 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode contacts.getTopPeers#973478b6: field flags: %w", )
		}
	}
	.Correspondents = .Flags.Has(0)
	.BotsPm = .Flags.Has(1)
	.BotsInline = .Flags.Has(2)
	.PhoneCalls = .Flags.Has(3)
	.ForwardUsers = .Flags.Has(4)
	.ForwardChats = .Flags.Has(5)
	.Groups = .Flags.Has(10)
	.Channels = .Flags.Has(15)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.getTopPeers#973478b6: field offset: %w", )
		}
		.Offset = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.getTopPeers#973478b6: field limit: %w", )
		}
		.Limit = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.getTopPeers#973478b6: field hash: %w", )
		}
		.Hash = 
	}
	return nil
}

// SetCorrespondents sets value of Correspondents conditional field.
func ( *ContactsGetTopPeersRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Correspondents = true
	} else {
		.Flags.Unset(0)
		.Correspondents = false
	}
}

// GetCorrespondents returns value of Correspondents conditional field.
func ( *ContactsGetTopPeersRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetBotsPm sets value of BotsPm conditional field.
func ( *ContactsGetTopPeersRequest) ( bool) {
	if  {
		.Flags.Set(1)
		.BotsPm = true
	} else {
		.Flags.Unset(1)
		.BotsPm = false
	}
}

// GetBotsPm returns value of BotsPm conditional field.
func ( *ContactsGetTopPeersRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetBotsInline sets value of BotsInline conditional field.
func ( *ContactsGetTopPeersRequest) ( bool) {
	if  {
		.Flags.Set(2)
		.BotsInline = true
	} else {
		.Flags.Unset(2)
		.BotsInline = false
	}
}

// GetBotsInline returns value of BotsInline conditional field.
func ( *ContactsGetTopPeersRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetPhoneCalls sets value of PhoneCalls conditional field.
func ( *ContactsGetTopPeersRequest) ( bool) {
	if  {
		.Flags.Set(3)
		.PhoneCalls = true
	} else {
		.Flags.Unset(3)
		.PhoneCalls = false
	}
}

// GetPhoneCalls returns value of PhoneCalls conditional field.
func ( *ContactsGetTopPeersRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetForwardUsers sets value of ForwardUsers conditional field.
func ( *ContactsGetTopPeersRequest) ( bool) {
	if  {
		.Flags.Set(4)
		.ForwardUsers = true
	} else {
		.Flags.Unset(4)
		.ForwardUsers = false
	}
}

// GetForwardUsers returns value of ForwardUsers conditional field.
func ( *ContactsGetTopPeersRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// SetForwardChats sets value of ForwardChats conditional field.
func ( *ContactsGetTopPeersRequest) ( bool) {
	if  {
		.Flags.Set(5)
		.ForwardChats = true
	} else {
		.Flags.Unset(5)
		.ForwardChats = false
	}
}

// GetForwardChats returns value of ForwardChats conditional field.
func ( *ContactsGetTopPeersRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

// SetGroups sets value of Groups conditional field.
func ( *ContactsGetTopPeersRequest) ( bool) {
	if  {
		.Flags.Set(10)
		.Groups = true
	} else {
		.Flags.Unset(10)
		.Groups = false
	}
}

// GetGroups returns value of Groups conditional field.
func ( *ContactsGetTopPeersRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(10)
}

// SetChannels sets value of Channels conditional field.
func ( *ContactsGetTopPeersRequest) ( bool) {
	if  {
		.Flags.Set(15)
		.Channels = true
	} else {
		.Flags.Unset(15)
		.Channels = false
	}
}

// GetChannels returns value of Channels conditional field.
func ( *ContactsGetTopPeersRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(15)
}

// GetOffset returns value of Offset field.
func ( *ContactsGetTopPeersRequest) () ( int) {
	if  == nil {
		return
	}
	return .Offset
}

// GetLimit returns value of Limit field.
func ( *ContactsGetTopPeersRequest) () ( int) {
	if  == nil {
		return
	}
	return .Limit
}

// GetHash returns value of Hash field.
func ( *ContactsGetTopPeersRequest) () ( int64) {
	if  == nil {
		return
	}
	return .Hash
}

// ContactsGetTopPeers invokes method contacts.getTopPeers#973478b6 returning error if any.
// Get most used peers
//
// Possible errors:
//
//	400 TYPES_EMPTY: No top peer type was provided.
//
// See https://core.telegram.org/method/contacts.getTopPeers for reference.
func ( *Client) ( context.Context,  *ContactsGetTopPeersRequest) (ContactsTopPeersClass, error) {
	var  ContactsTopPeersBox

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return .TopPeers, nil
}