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

// ChannelsSearchPostsRequest represents TL type `channels.searchPosts#f2c4f24d`.
// Globally search for posts from public channels »¹ (including those we aren't a
// member of) containing either a specific hashtag, or a full text query.
// Exactly one of query and hashtag must be set.
//
// Links:
//  1. https://core.telegram.org/api/channel
//
// See https://core.telegram.org/method/channels.searchPosts for reference.
type ChannelsSearchPostsRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// The hashtag to search, without the # character.
	//
	// Use SetHashtag and GetHashtag helpers.
	Hashtag string
	// The full text query: each user has a limited amount of free full text search slots,
	// after which payment is required, see here »¹ for more info on the full flow.
	//
	// Links:
	//  1) https://core.telegram.org/api/search#posts-tab
	//
	// Use SetQuery and GetQuery helpers.
	Query string
	// Initially 0, then set to the next_rate parameter of messages.messagesSlice¹, or if
	// that is absent, the date of the last returned message.
	//
	// 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
	// Maximum number of results to return, see pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Limit int
	// For full text post searches (query), allows payment of the specified amount of Stars
	// for the search, see here »¹ for more info on the full flow.
	//
	// Links:
	//  1) https://core.telegram.org/api/search#posts-tab
	//
	// Use SetAllowPaidStars and GetAllowPaidStars helpers.
	AllowPaidStars int64
}

// ChannelsSearchPostsRequestTypeID is TL type id of ChannelsSearchPostsRequest.
const ChannelsSearchPostsRequestTypeID = 0xf2c4f24d

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

func ( *ChannelsSearchPostsRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Hashtag == "") {
		return false
	}
	if !(.Query == "") {
		return false
	}
	if !(.OffsetRate == 0) {
		return false
	}
	if !(.OffsetPeer == nil) {
		return false
	}
	if !(.OffsetID == 0) {
		return false
	}
	if !(.Limit == 0) {
		return false
	}
	if !(.AllowPaidStars == 0) {
		return false
	}

	return true
}

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

// FillFrom fills ChannelsSearchPostsRequest from given interface.
func ( *ChannelsSearchPostsRequest) ( interface {
	() ( string,  bool)
	() ( string,  bool)
	() ( int)
	() ( InputPeerClass)
	() ( int)
	() ( int)
	() ( int64,  bool)
}) {
	if ,  := .();  {
		.Hashtag = 
	}

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

	.OffsetRate = .()
	.OffsetPeer = .()
	.OffsetID = .()
	.Limit = .()
	if ,  := .();  {
		.AllowPaidStars = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*ChannelsSearchPostsRequest) () string {
	return "channels.searchPosts"
}

// TypeInfo returns info about TL type.
func ( *ChannelsSearchPostsRequest) () tdp.Type {
	 := tdp.Type{
		Name: "channels.searchPosts",
		ID:   ChannelsSearchPostsRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Hashtag",
			SchemaName: "hashtag",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Query",
			SchemaName: "query",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "OffsetRate",
			SchemaName: "offset_rate",
		},
		{
			Name:       "OffsetPeer",
			SchemaName: "offset_peer",
		},
		{
			Name:       "OffsetID",
			SchemaName: "offset_id",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
		{
			Name:       "AllowPaidStars",
			SchemaName: "allow_paid_stars",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *ChannelsSearchPostsRequest) () {
	if !(.Hashtag == "") {
		.Flags.Set(0)
	}
	if !(.Query == "") {
		.Flags.Set(1)
	}
	if !(.AllowPaidStars == 0) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *ChannelsSearchPostsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channels.searchPosts#f2c4f24d as nil")
	}
	.PutID(ChannelsSearchPostsRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChannelsSearchPostsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode channels.searchPosts#f2c4f24d as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode channels.searchPosts#f2c4f24d: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutString(.Hashtag)
	}
	if .Flags.Has(1) {
		.PutString(.Query)
	}
	.PutInt(.OffsetRate)
	if .OffsetPeer == nil {
		return fmt.Errorf("unable to encode channels.searchPosts#f2c4f24d: field offset_peer is nil")
	}
	if  := .OffsetPeer.Encode();  != nil {
		return fmt.Errorf("unable to encode channels.searchPosts#f2c4f24d: field offset_peer: %w", )
	}
	.PutInt(.OffsetID)
	.PutInt(.Limit)
	if .Flags.Has(2) {
		.PutLong(.AllowPaidStars)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *ChannelsSearchPostsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channels.searchPosts#f2c4f24d to nil")
	}
	if  := .ConsumeID(ChannelsSearchPostsRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode channels.searchPosts#f2c4f24d: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ChannelsSearchPostsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode channels.searchPosts#f2c4f24d to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode channels.searchPosts#f2c4f24d: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode channels.searchPosts#f2c4f24d: field hashtag: %w", )
		}
		.Hashtag = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode channels.searchPosts#f2c4f24d: field query: %w", )
		}
		.Query = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode channels.searchPosts#f2c4f24d: field offset_rate: %w", )
		}
		.OffsetRate = 
	}
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode channels.searchPosts#f2c4f24d: field offset_peer: %w", )
		}
		.OffsetPeer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode channels.searchPosts#f2c4f24d: field offset_id: %w", )
		}
		.OffsetID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode channels.searchPosts#f2c4f24d: field limit: %w", )
		}
		.Limit = 
	}
	if .Flags.Has(2) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode channels.searchPosts#f2c4f24d: field allow_paid_stars: %w", )
		}
		.AllowPaidStars = 
	}
	return nil
}

// SetHashtag sets value of Hashtag conditional field.
func ( *ChannelsSearchPostsRequest) ( string) {
	.Flags.Set(0)
	.Hashtag = 
}

// GetHashtag returns value of Hashtag conditional field and
// boolean which is true if field was set.
func ( *ChannelsSearchPostsRequest) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Hashtag, true
}

// SetQuery sets value of Query conditional field.
func ( *ChannelsSearchPostsRequest) ( string) {
	.Flags.Set(1)
	.Query = 
}

// GetQuery returns value of Query conditional field and
// boolean which is true if field was set.
func ( *ChannelsSearchPostsRequest) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Query, true
}

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

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

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

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

// SetAllowPaidStars sets value of AllowPaidStars conditional field.
func ( *ChannelsSearchPostsRequest) ( int64) {
	.Flags.Set(2)
	.AllowPaidStars = 
}

// GetAllowPaidStars returns value of AllowPaidStars conditional field and
// boolean which is true if field was set.
func ( *ChannelsSearchPostsRequest) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .AllowPaidStars, true
}

// ChannelsSearchPosts invokes method channels.searchPosts#f2c4f24d returning error if any.
// Globally search for posts from public channels »¹ (including those we aren't a
// member of) containing either a specific hashtag, or a full text query.
// Exactly one of query and hashtag must be set.
//
// Links:
//  1. https://core.telegram.org/api/channel
//
// Possible errors:
//
//	420 FROZEN_METHOD_INVALID: The current account is frozen, and thus cannot execute the specified action.
//	403 PREMIUM_ACCOUNT_REQUIRED: A premium account is required to execute this action.
//
// See https://core.telegram.org/method/channels.searchPosts for reference.
func ( *Client) ( context.Context,  *ChannelsSearchPostsRequest) (MessagesMessagesClass, error) {
	var  MessagesMessagesBox

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