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

// ContactsSearchRequest represents TL type `contacts.search#11f812d8`.
// Returns users found by username substring.
//
// See https://core.telegram.org/method/contacts.search for reference.
type ContactsSearchRequest struct {
	// Target substring
	Q string
	// Maximum number of users to be returned
	Limit int
}

// ContactsSearchRequestTypeID is TL type id of ContactsSearchRequest.
const ContactsSearchRequestTypeID = 0x11f812d8

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

func ( *ContactsSearchRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Q == "") {
		return false
	}
	if !(.Limit == 0) {
		return false
	}

	return true
}

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

// FillFrom fills ContactsSearchRequest from given interface.
func ( *ContactsSearchRequest) ( interface {
	() ( string)
	() ( int)
}) {
	.Q = .()
	.Limit = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *ContactsSearchRequest) () tdp.Type {
	 := tdp.Type{
		Name: "contacts.search",
		ID:   ContactsSearchRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Q",
			SchemaName: "q",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *ContactsSearchRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.search#11f812d8 as nil")
	}
	.PutID(ContactsSearchRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ContactsSearchRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode contacts.search#11f812d8 as nil")
	}
	.PutString(.Q)
	.PutInt(.Limit)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *ContactsSearchRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode contacts.search#11f812d8 to nil")
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.search#11f812d8: field q: %w", )
		}
		.Q = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode contacts.search#11f812d8: field limit: %w", )
		}
		.Limit = 
	}
	return nil
}

// GetQ returns value of Q field.
func ( *ContactsSearchRequest) () ( string) {
	if  == nil {
		return
	}
	return .Q
}

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

// ContactsSearch invokes method contacts.search#11f812d8 returning error if any.
// Returns users found by username substring.
//
// Possible errors:
//
//	400 QUERY_TOO_SHORT: The query string is too short.
//	400 SEARCH_QUERY_EMPTY: The search query is empty.
//
// See https://core.telegram.org/method/contacts.search for reference.
func ( *Client) ( context.Context,  *ContactsSearchRequest) (*ContactsFound, error) {
	var  ContactsFound

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