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

// SearchPostsFlood represents TL type `searchPostsFlood#3e0b5b6a`.
// Indicates if the specified global post search »¹ requires payment.
//
// Links:
//  1. https://core.telegram.org/api/search#posts-tab
//
// See https://core.telegram.org/constructor/searchPostsFlood for reference.
type SearchPostsFlood struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// The specified query is free (and it will not use up free search slots).
	QueryIsFree bool
	// Total number of daily free search slots.
	TotalDaily int
	// Remaining number of free search slots.
	Remains int
	// If there are no more search slots, specifies the unixtime when more search slots will
	// be available.
	//
	// Use SetWaitTill and GetWaitTill helpers.
	WaitTill int
	// The number of Telegram Stars¹ to pay for each non-free search.
	//
	// Links:
	//  1) https://core.telegram.org/api/stars
	StarsAmount int64
}

// SearchPostsFloodTypeID is TL type id of SearchPostsFlood.
const SearchPostsFloodTypeID = 0x3e0b5b6a

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

func ( *SearchPostsFlood) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.QueryIsFree == false) {
		return false
	}
	if !(.TotalDaily == 0) {
		return false
	}
	if !(.Remains == 0) {
		return false
	}
	if !(.WaitTill == 0) {
		return false
	}
	if !(.StarsAmount == 0) {
		return false
	}

	return true
}

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

// FillFrom fills SearchPostsFlood from given interface.
func ( *SearchPostsFlood) ( interface {
	() ( bool)
	() ( int)
	() ( int)
	() ( int,  bool)
	() ( int64)
}) {
	.QueryIsFree = .()
	.TotalDaily = .()
	.Remains = .()
	if ,  := .();  {
		.WaitTill = 
	}

	.StarsAmount = .()
}

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

// TypeName returns name of type in TL schema.
func (*SearchPostsFlood) () string {
	return "searchPostsFlood"
}

// TypeInfo returns info about TL type.
func ( *SearchPostsFlood) () tdp.Type {
	 := tdp.Type{
		Name: "searchPostsFlood",
		ID:   SearchPostsFloodTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "QueryIsFree",
			SchemaName: "query_is_free",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "TotalDaily",
			SchemaName: "total_daily",
		},
		{
			Name:       "Remains",
			SchemaName: "remains",
		},
		{
			Name:       "WaitTill",
			SchemaName: "wait_till",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "StarsAmount",
			SchemaName: "stars_amount",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *SearchPostsFlood) () {
	if !(.QueryIsFree == false) {
		.Flags.Set(0)
	}
	if !(.WaitTill == 0) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *SearchPostsFlood) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode searchPostsFlood#3e0b5b6a as nil")
	}
	.PutID(SearchPostsFloodTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *SearchPostsFlood) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode searchPostsFlood#3e0b5b6a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode searchPostsFlood#3e0b5b6a: field flags: %w", )
	}
	.PutInt(.TotalDaily)
	.PutInt(.Remains)
	if .Flags.Has(1) {
		.PutInt(.WaitTill)
	}
	.PutLong(.StarsAmount)
	return nil
}

// Decode implements bin.Decoder.
func ( *SearchPostsFlood) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode searchPostsFlood#3e0b5b6a to nil")
	}
	if  := .ConsumeID(SearchPostsFloodTypeID);  != nil {
		return fmt.Errorf("unable to decode searchPostsFlood#3e0b5b6a: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *SearchPostsFlood) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode searchPostsFlood#3e0b5b6a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode searchPostsFlood#3e0b5b6a: field flags: %w", )
		}
	}
	.QueryIsFree = .Flags.Has(0)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode searchPostsFlood#3e0b5b6a: field total_daily: %w", )
		}
		.TotalDaily = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode searchPostsFlood#3e0b5b6a: field remains: %w", )
		}
		.Remains = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode searchPostsFlood#3e0b5b6a: field wait_till: %w", )
		}
		.WaitTill = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode searchPostsFlood#3e0b5b6a: field stars_amount: %w", )
		}
		.StarsAmount = 
	}
	return nil
}

// SetQueryIsFree sets value of QueryIsFree conditional field.
func ( *SearchPostsFlood) ( bool) {
	if  {
		.Flags.Set(0)
		.QueryIsFree = true
	} else {
		.Flags.Unset(0)
		.QueryIsFree = false
	}
}

// GetQueryIsFree returns value of QueryIsFree conditional field.
func ( *SearchPostsFlood) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetTotalDaily returns value of TotalDaily field.
func ( *SearchPostsFlood) () ( int) {
	if  == nil {
		return
	}
	return .TotalDaily
}

// GetRemains returns value of Remains field.
func ( *SearchPostsFlood) () ( int) {
	if  == nil {
		return
	}
	return .Remains
}

// SetWaitTill sets value of WaitTill conditional field.
func ( *SearchPostsFlood) ( int) {
	.Flags.Set(1)
	.WaitTill = 
}

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

// GetStarsAmount returns value of StarsAmount field.
func ( *SearchPostsFlood) () ( int64) {
	if  == nil {
		return
	}
	return .StarsAmount
}