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

// MessagesSearchGlobalRequest represents TL type `messages.searchGlobal#4bc6589a`.
// Search for messages and peers globally
//
// See https://core.telegram.org/method/messages.searchGlobal for reference.
type MessagesSearchGlobalRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Peer folder ID, for more info click here¹
	//
	// Links:
	//  1) https://core.telegram.org/api/folders#peer-folders
	//
	// Use SetFolderID and GetFolderID helpers.
	FolderID int
	// Query
	Q string
	// Global search filter
	Filter MessagesFilterClass
	// If a positive value was specified, the method will return only messages with date
	// bigger than min_date
	MinDate int
	// If a positive value was transferred, the method will return only messages with date
	// smaller than max_date
	MaxDate int
	// Initially 0, then set to the next_rate parameter of messages.messagesSlice¹
	//
	// Links:
	//  1) https://core.telegram.org/constructor/messages.messagesSlice
	OffsetRate int
	// Offsets for pagination, for more info click here¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	OffsetPeer InputPeerClass
	// Offsets for pagination, for more info click here¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	OffsetID int
	// Offsets for pagination, for more info click here¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Limit int
}

// MessagesSearchGlobalRequestTypeID is TL type id of MessagesSearchGlobalRequest.
const MessagesSearchGlobalRequestTypeID = 0x4bc6589a

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

func ( *MessagesSearchGlobalRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.FolderID == 0) {
		return false
	}
	if !(.Q == "") {
		return false
	}
	if !(.Filter == nil) {
		return false
	}
	if !(.MinDate == 0) {
		return false
	}
	if !(.MaxDate == 0) {
		return false
	}
	if !(.OffsetRate == 0) {
		return false
	}
	if !(.OffsetPeer == nil) {
		return false
	}
	if !(.OffsetID == 0) {
		return false
	}
	if !(.Limit == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSearchGlobalRequest from given interface.
func ( *MessagesSearchGlobalRequest) ( interface {
	() ( int,  bool)
	() ( string)
	() ( MessagesFilterClass)
	() ( int)
	() ( int)
	() ( int)
	() ( InputPeerClass)
	() ( int)
	() ( int)
}) {
	if ,  := .();  {
		.FolderID = 
	}

	.Q = .()
	.Filter = .()
	.MinDate = .()
	.MaxDate = .()
	.OffsetRate = .()
	.OffsetPeer = .()
	.OffsetID = .()
	.Limit = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesSearchGlobalRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.searchGlobal",
		ID:   MessagesSearchGlobalRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "FolderID",
			SchemaName: "folder_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Q",
			SchemaName: "q",
		},
		{
			Name:       "Filter",
			SchemaName: "filter",
		},
		{
			Name:       "MinDate",
			SchemaName: "min_date",
		},
		{
			Name:       "MaxDate",
			SchemaName: "max_date",
		},
		{
			Name:       "OffsetRate",
			SchemaName: "offset_rate",
		},
		{
			Name:       "OffsetPeer",
			SchemaName: "offset_peer",
		},
		{
			Name:       "OffsetID",
			SchemaName: "offset_id",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *MessagesSearchGlobalRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.searchGlobal#4bc6589a as nil")
	}
	.PutID(MessagesSearchGlobalRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesSearchGlobalRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.searchGlobal#4bc6589a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.searchGlobal#4bc6589a: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutInt(.FolderID)
	}
	.PutString(.Q)
	if .Filter == nil {
		return fmt.Errorf("unable to encode messages.searchGlobal#4bc6589a: field filter is nil")
	}
	if  := .Filter.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.searchGlobal#4bc6589a: field filter: %w", )
	}
	.PutInt(.MinDate)
	.PutInt(.MaxDate)
	.PutInt(.OffsetRate)
	if .OffsetPeer == nil {
		return fmt.Errorf("unable to encode messages.searchGlobal#4bc6589a: field offset_peer is nil")
	}
	if  := .OffsetPeer.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.searchGlobal#4bc6589a: field offset_peer: %w", )
	}
	.PutInt(.OffsetID)
	.PutInt(.Limit)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesSearchGlobalRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.searchGlobal#4bc6589a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field folder_id: %w", )
		}
		.FolderID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field q: %w", )
		}
		.Q = 
	}
	{
		,  := DecodeMessagesFilter()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field filter: %w", )
		}
		.Filter = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field min_date: %w", )
		}
		.MinDate = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field max_date: %w", )
		}
		.MaxDate = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field offset_rate: %w", )
		}
		.OffsetRate = 
	}
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field offset_peer: %w", )
		}
		.OffsetPeer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field offset_id: %w", )
		}
		.OffsetID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchGlobal#4bc6589a: field limit: %w", )
		}
		.Limit = 
	}
	return nil
}

// SetFolderID sets value of FolderID conditional field.
func ( *MessagesSearchGlobalRequest) ( int) {
	.Flags.Set(0)
	.FolderID = 
}

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

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

// GetFilter returns value of Filter field.
func ( *MessagesSearchGlobalRequest) () ( MessagesFilterClass) {
	if  == nil {
		return
	}
	return .Filter
}

// GetMinDate returns value of MinDate field.
func ( *MessagesSearchGlobalRequest) () ( int) {
	if  == nil {
		return
	}
	return .MinDate
}

// GetMaxDate returns value of MaxDate field.
func ( *MessagesSearchGlobalRequest) () ( int) {
	if  == nil {
		return
	}
	return .MaxDate
}

// GetOffsetRate returns value of OffsetRate field.
func ( *MessagesSearchGlobalRequest) () ( int) {
	if  == nil {
		return
	}
	return .OffsetRate
}

// GetOffsetPeer returns value of OffsetPeer field.
func ( *MessagesSearchGlobalRequest) () ( InputPeerClass) {
	if  == nil {
		return
	}
	return .OffsetPeer
}

// GetOffsetID returns value of OffsetID field.
func ( *MessagesSearchGlobalRequest) () ( int) {
	if  == nil {
		return
	}
	return .OffsetID
}

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

// MessagesSearchGlobal invokes method messages.searchGlobal#4bc6589a returning error if any.
// Search for messages and peers globally
//
// Possible errors:
//
//	400 FOLDER_ID_INVALID: Invalid folder ID.
//	400 SEARCH_QUERY_EMPTY: The search query is empty.
//
// See https://core.telegram.org/method/messages.searchGlobal for reference.
func ( *Client) ( context.Context,  *MessagesSearchGlobalRequest) (MessagesMessagesClass, error) {
	var  MessagesMessagesBox

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