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

// MessagesGetSearchCountersRequest represents TL type `messages.getSearchCounters#ae7cc1`.
// Get the number of results that would be found by a messages.search¹ call with the
// same parameters
//
// Links:
//  1. https://core.telegram.org/method/messages.search
//
// See https://core.telegram.org/method/messages.getSearchCounters for reference.
type MessagesGetSearchCountersRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Peer where to search
	Peer InputPeerClass
	// If set, consider only messages within the specified forum topic¹
	//
	// Links:
	//  1) https://core.telegram.org/api/forum#forum-topics
	//
	// Use SetTopMsgID and GetTopMsgID helpers.
	TopMsgID int
	// Search filters
	Filters []MessagesFilterClass
}

// MessagesGetSearchCountersRequestTypeID is TL type id of MessagesGetSearchCountersRequest.
const MessagesGetSearchCountersRequestTypeID = 0xae7cc1

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

func ( *MessagesGetSearchCountersRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.TopMsgID == 0) {
		return false
	}
	if !(.Filters == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesGetSearchCountersRequest from given interface.
func ( *MessagesGetSearchCountersRequest) ( interface {
	() ( InputPeerClass)
	() ( int,  bool)
	() ( []MessagesFilterClass)
}) {
	.Peer = .()
	if ,  := .();  {
		.TopMsgID = 
	}

	.Filters = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesGetSearchCountersRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.getSearchCounters",
		ID:   MessagesGetSearchCountersRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "TopMsgID",
			SchemaName: "top_msg_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Filters",
			SchemaName: "filters",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesGetSearchCountersRequest) () {
	if !(.TopMsgID == 0) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesGetSearchCountersRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.getSearchCounters#ae7cc1 as nil")
	}
	.PutID(MessagesGetSearchCountersRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesGetSearchCountersRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.getSearchCounters#ae7cc1 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.getSearchCounters#ae7cc1: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode messages.getSearchCounters#ae7cc1: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.getSearchCounters#ae7cc1: field peer: %w", )
	}
	if .Flags.Has(0) {
		.PutInt(.TopMsgID)
	}
	.PutVectorHeader(len(.Filters))
	for ,  := range .Filters {
		if  == nil {
			return fmt.Errorf("unable to encode messages.getSearchCounters#ae7cc1: field filters element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.getSearchCounters#ae7cc1: field filters element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesGetSearchCountersRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.getSearchCounters#ae7cc1 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.getSearchCounters#ae7cc1: field flags: %w", )
		}
	}
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getSearchCounters#ae7cc1: field peer: %w", )
		}
		.Peer = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getSearchCounters#ae7cc1: field top_msg_id: %w", )
		}
		.TopMsgID = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getSearchCounters#ae7cc1: field filters: %w", )
		}

		if  > 0 {
			.Filters = make([]MessagesFilterClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessagesFilter()
			if  != nil {
				return fmt.Errorf("unable to decode messages.getSearchCounters#ae7cc1: field filters: %w", )
			}
			.Filters = append(.Filters, )
		}
	}
	return nil
}

// GetPeer returns value of Peer field.
func ( *MessagesGetSearchCountersRequest) () ( InputPeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// SetTopMsgID sets value of TopMsgID conditional field.
func ( *MessagesGetSearchCountersRequest) ( int) {
	.Flags.Set(0)
	.TopMsgID = 
}

// GetTopMsgID returns value of TopMsgID conditional field and
// boolean which is true if field was set.
func ( *MessagesGetSearchCountersRequest) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .TopMsgID, true
}

// GetFilters returns value of Filters field.
func ( *MessagesGetSearchCountersRequest) () ( []MessagesFilterClass) {
	if  == nil {
		return
	}
	return .Filters
}

// MapFilters returns field Filters wrapped in MessagesFilterClassArray helper.
func ( *MessagesGetSearchCountersRequest) () ( MessagesFilterClassArray) {
	return MessagesFilterClassArray(.Filters)
}

// MessagesGetSearchCounters invokes method messages.getSearchCounters#ae7cc1 returning error if any.
// Get the number of results that would be found by a messages.search¹ call with the
// same parameters
//
// Links:
//  1. https://core.telegram.org/method/messages.search
//
// Possible errors:
//
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/messages.getSearchCounters for reference.
func ( *Client) ( context.Context,  *MessagesGetSearchCountersRequest) ([]MessagesSearchCounter, error) {
	var  MessagesSearchCounterVector

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