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

// MessagesSearchRequest represents TL type `messages.search#a0fda762`.
// Search for messages.
//
// See https://core.telegram.org/method/messages.search for reference.
type MessagesSearchRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// User or chat, histories with which are searched, or (inputPeerEmpty)¹ constructor to
	// search in all private chats and normal groups (not channels) »². Use messages
	// searchGlobal³ to search globally in all chats, groups, supergroups and channels.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/inputPeerEmpty
	//  2) https://core.telegram.org/api/channel
	//  3) https://core.telegram.org/method/messages.searchGlobal
	Peer InputPeerClass
	// Text search request
	Q string
	// Only return messages sent by the specified user ID
	//
	// Use SetFromID and GetFromID helpers.
	FromID InputPeerClass
	// Thread ID¹
	//
	// Links:
	//  1) https://core.telegram.org/api/threads
	//
	// Use SetTopMsgID and GetTopMsgID helpers.
	TopMsgID int
	// Filter to return only specified message types
	Filter MessagesFilterClass
	// If a positive value was transferred, only messages with a sending date bigger than the
	// transferred one will be returned
	MinDate int
	// If a positive value was transferred, only messages with a sending date smaller than
	// the transferred one will be returned
	MaxDate int
	// Only return messages starting from the specified message ID
	OffsetID int
	// Additional offset¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	AddOffset int
	// Number of results to return¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Limit int
	// Maximum message ID to return¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	MaxID int
	// Minimum message ID to return¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	MinID int
	// Hash¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Hash int64
}

// MessagesSearchRequestTypeID is TL type id of MessagesSearchRequest.
const MessagesSearchRequestTypeID = 0xa0fda762

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

func ( *MessagesSearchRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Q == "") {
		return false
	}
	if !(.FromID == nil) {
		return false
	}
	if !(.TopMsgID == 0) {
		return false
	}
	if !(.Filter == nil) {
		return false
	}
	if !(.MinDate == 0) {
		return false
	}
	if !(.MaxDate == 0) {
		return false
	}
	if !(.OffsetID == 0) {
		return false
	}
	if !(.AddOffset == 0) {
		return false
	}
	if !(.Limit == 0) {
		return false
	}
	if !(.MaxID == 0) {
		return false
	}
	if !(.MinID == 0) {
		return false
	}
	if !(.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSearchRequest from given interface.
func ( *MessagesSearchRequest) ( interface {
	() ( InputPeerClass)
	() ( string)
	() ( InputPeerClass,  bool)
	() ( int,  bool)
	() ( MessagesFilterClass)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( int64)
}) {
	.Peer = .()
	.Q = .()
	if ,  := .();  {
		.FromID = 
	}

	if ,  := .();  {
		.TopMsgID = 
	}

	.Filter = .()
	.MinDate = .()
	.MaxDate = .()
	.OffsetID = .()
	.AddOffset = .()
	.Limit = .()
	.MaxID = .()
	.MinID = .()
	.Hash = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesSearchRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.search",
		ID:   MessagesSearchRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Q",
			SchemaName: "q",
		},
		{
			Name:       "FromID",
			SchemaName: "from_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "TopMsgID",
			SchemaName: "top_msg_id",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Filter",
			SchemaName: "filter",
		},
		{
			Name:       "MinDate",
			SchemaName: "min_date",
		},
		{
			Name:       "MaxDate",
			SchemaName: "max_date",
		},
		{
			Name:       "OffsetID",
			SchemaName: "offset_id",
		},
		{
			Name:       "AddOffset",
			SchemaName: "add_offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
		{
			Name:       "MaxID",
			SchemaName: "max_id",
		},
		{
			Name:       "MinID",
			SchemaName: "min_id",
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *MessagesSearchRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.search#a0fda762 as nil")
	}
	.PutID(MessagesSearchRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesSearchRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.search#a0fda762 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.search#a0fda762: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode messages.search#a0fda762: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.search#a0fda762: field peer: %w", )
	}
	.PutString(.Q)
	if .Flags.Has(0) {
		if .FromID == nil {
			return fmt.Errorf("unable to encode messages.search#a0fda762: field from_id is nil")
		}
		if  := .FromID.Encode();  != nil {
			return fmt.Errorf("unable to encode messages.search#a0fda762: field from_id: %w", )
		}
	}
	if .Flags.Has(1) {
		.PutInt(.TopMsgID)
	}
	if .Filter == nil {
		return fmt.Errorf("unable to encode messages.search#a0fda762: field filter is nil")
	}
	if  := .Filter.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.search#a0fda762: field filter: %w", )
	}
	.PutInt(.MinDate)
	.PutInt(.MaxDate)
	.PutInt(.OffsetID)
	.PutInt(.AddOffset)
	.PutInt(.Limit)
	.PutInt(.MaxID)
	.PutInt(.MinID)
	.PutLong(.Hash)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesSearchRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.search#a0fda762 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field flags: %w", )
		}
	}
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field q: %w", )
		}
		.Q = 
	}
	if .Flags.Has(0) {
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field from_id: %w", )
		}
		.FromID = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field top_msg_id: %w", )
		}
		.TopMsgID = 
	}
	{
		,  := DecodeMessagesFilter()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field filter: %w", )
		}
		.Filter = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field min_date: %w", )
		}
		.MinDate = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field max_date: %w", )
		}
		.MaxDate = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field offset_id: %w", )
		}
		.OffsetID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field add_offset: %w", )
		}
		.AddOffset = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field limit: %w", )
		}
		.Limit = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field max_id: %w", )
		}
		.MaxID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field min_id: %w", )
		}
		.MinID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode messages.search#a0fda762: field hash: %w", )
		}
		.Hash = 
	}
	return nil
}

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

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

// SetFromID sets value of FromID conditional field.
func ( *MessagesSearchRequest) ( InputPeerClass) {
	.Flags.Set(0)
	.FromID = 
}

// GetFromID returns value of FromID conditional field and
// boolean which is true if field was set.
func ( *MessagesSearchRequest) () ( InputPeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .FromID, true
}

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

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

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

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

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

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

// GetAddOffset returns value of AddOffset field.
func ( *MessagesSearchRequest) () ( int) {
	if  == nil {
		return
	}
	return .AddOffset
}

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

// GetMaxID returns value of MaxID field.
func ( *MessagesSearchRequest) () ( int) {
	if  == nil {
		return
	}
	return .MaxID
}

// GetMinID returns value of MinID field.
func ( *MessagesSearchRequest) () ( int) {
	if  == nil {
		return
	}
	return .MinID
}

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

// MessagesSearch invokes method messages.search#a0fda762 returning error if any.
// Search for messages.
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	400 CHANNEL_PRIVATE: You haven't joined this channel/supergroup.
//	403 CHAT_ADMIN_REQUIRED: You must be an admin in this chat to do this.
//	400 CHAT_ID_INVALID: The provided chat id is invalid.
//	400 FROM_PEER_INVALID: The specified from_id is invalid.
//	400 INPUT_FILTER_INVALID: The specified filter is invalid.
//	400 INPUT_USER_DEACTIVATED: The specified user was deleted.
//	400 MSG_ID_INVALID: Invalid message ID provided.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//	400 PEER_ID_NOT_SUPPORTED: The provided peer ID is not supported.
//	400 SEARCH_QUERY_EMPTY: The search query is empty.
//	400 USER_ID_INVALID: The provided user ID is invalid.
//
// See https://core.telegram.org/method/messages.search for reference.
func ( *Client) ( context.Context,  *MessagesSearchRequest) (MessagesMessagesClass, error) {
	var  MessagesMessagesBox

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