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

// StoriesSearchPostsRequest represents TL type `stories.searchPosts#d1810907`.
// Globally search for stories¹ using a hashtag or a location media area², see here
// »³ for more info on the full flow.
// Either hashtag or area must be set when invoking the method.
//
// Links:
//  1. https://core.telegram.org/api/stories
//  2. https://core.telegram.org/api/stories#location-tags
//  3. https://core.telegram.org/api/stories#searching-stories
//
// See https://core.telegram.org/method/stories.searchPosts for reference.
type StoriesSearchPostsRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Hashtag (without the #)
	//
	// Use SetHashtag and GetHashtag helpers.
	Hashtag string
	// A mediaAreaGeoPoint¹ or a mediaAreaVenue².  Note mediaAreaGeoPoint³ areas may be
	// searched only if they have an associated address.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/mediaAreaGeoPoint
	//  2) https://core.telegram.org/constructor/mediaAreaVenue
	//  3) https://core.telegram.org/constructor/mediaAreaGeoPoint
	//
	// Use SetArea and GetArea helpers.
	Area MediaAreaClass
	// If set, returns only stories posted by this peer.
	//
	// Use SetPeer and GetPeer helpers.
	Peer InputPeerClass
	// Offset for pagination¹: initially an empty string, then the next_offset from the
	// previously returned stories.foundStories².
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	//  2) https://core.telegram.org/constructor/stories.foundStories
	Offset string
	// Maximum number of results to return, see pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	Limit int
}

// StoriesSearchPostsRequestTypeID is TL type id of StoriesSearchPostsRequest.
const StoriesSearchPostsRequestTypeID = 0xd1810907

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

func ( *StoriesSearchPostsRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Hashtag == "") {
		return false
	}
	if !(.Area == nil) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Offset == "") {
		return false
	}
	if !(.Limit == 0) {
		return false
	}

	return true
}

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

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

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

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

	.Offset = .()
	.Limit = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StoriesSearchPostsRequest) () tdp.Type {
	 := tdp.Type{
		Name: "stories.searchPosts",
		ID:   StoriesSearchPostsRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Hashtag",
			SchemaName: "hashtag",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Area",
			SchemaName: "area",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Offset",
			SchemaName: "offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StoriesSearchPostsRequest) () {
	if !(.Hashtag == "") {
		.Flags.Set(0)
	}
	if !(.Area == nil) {
		.Flags.Set(1)
	}
	if !(.Peer == nil) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *StoriesSearchPostsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.searchPosts#d1810907 as nil")
	}
	.PutID(StoriesSearchPostsRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StoriesSearchPostsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.searchPosts#d1810907 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode stories.searchPosts#d1810907: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutString(.Hashtag)
	}
	if .Flags.Has(1) {
		if .Area == nil {
			return fmt.Errorf("unable to encode stories.searchPosts#d1810907: field area is nil")
		}
		if  := .Area.Encode();  != nil {
			return fmt.Errorf("unable to encode stories.searchPosts#d1810907: field area: %w", )
		}
	}
	if .Flags.Has(2) {
		if .Peer == nil {
			return fmt.Errorf("unable to encode stories.searchPosts#d1810907: field peer is nil")
		}
		if  := .Peer.Encode();  != nil {
			return fmt.Errorf("unable to encode stories.searchPosts#d1810907: field peer: %w", )
		}
	}
	.PutString(.Offset)
	.PutInt(.Limit)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StoriesSearchPostsRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode stories.searchPosts#d1810907 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode stories.searchPosts#d1810907: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode stories.searchPosts#d1810907: field hashtag: %w", )
		}
		.Hashtag = 
	}
	if .Flags.Has(1) {
		,  := DecodeMediaArea()
		if  != nil {
			return fmt.Errorf("unable to decode stories.searchPosts#d1810907: field area: %w", )
		}
		.Area = 
	}
	if .Flags.Has(2) {
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode stories.searchPosts#d1810907: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode stories.searchPosts#d1810907: field offset: %w", )
		}
		.Offset = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode stories.searchPosts#d1810907: field limit: %w", )
		}
		.Limit = 
	}
	return nil
}

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

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

// SetArea sets value of Area conditional field.
func ( *StoriesSearchPostsRequest) ( MediaAreaClass) {
	.Flags.Set(1)
	.Area = 
}

// GetArea returns value of Area conditional field and
// boolean which is true if field was set.
func ( *StoriesSearchPostsRequest) () ( MediaAreaClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Area, true
}

// SetPeer sets value of Peer conditional field.
func ( *StoriesSearchPostsRequest) ( InputPeerClass) {
	.Flags.Set(2)
	.Peer = 
}

// GetPeer returns value of Peer conditional field and
// boolean which is true if field was set.
func ( *StoriesSearchPostsRequest) () ( InputPeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .Peer, true
}

// GetOffset returns value of Offset field.
func ( *StoriesSearchPostsRequest) () ( string) {
	if  == nil {
		return
	}
	return .Offset
}

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

// StoriesSearchPosts invokes method stories.searchPosts#d1810907 returning error if any.
// Globally search for stories¹ using a hashtag or a location media area², see here
// »³ for more info on the full flow.
// Either hashtag or area must be set when invoking the method.
//
// Links:
//  1. https://core.telegram.org/api/stories
//  2. https://core.telegram.org/api/stories#location-tags
//  3. https://core.telegram.org/api/stories#searching-stories
//
// Possible errors:
//
//	400 HASHTAG_INVALID: The specified hashtag is invalid.
//
// See https://core.telegram.org/method/stories.searchPosts for reference.
func ( *Client) ( context.Context,  *StoriesSearchPostsRequest) (*StoriesFoundStories, error) {
	var  StoriesFoundStories

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