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

// MessagesSearchCounter represents TL type `messages.searchCounter#e844ebff`.
// Indicates how many results would be found by a messages.search¹ call with the same
// parameters
//
// Links:
//  1. https://core.telegram.org/method/messages.search
//
// See https://core.telegram.org/constructor/messages.searchCounter for reference.
type MessagesSearchCounter struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, the results may be inexact
	Inexact bool
	// Provided message filter
	Filter MessagesFilterClass
	// Number of results that were found server-side
	Count int
}

// MessagesSearchCounterTypeID is TL type id of MessagesSearchCounter.
const MessagesSearchCounterTypeID = 0xe844ebff

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

func ( *MessagesSearchCounter) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Inexact == false) {
		return false
	}
	if !(.Filter == nil) {
		return false
	}
	if !(.Count == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSearchCounter from given interface.
func ( *MessagesSearchCounter) ( interface {
	() ( bool)
	() ( MessagesFilterClass)
	() ( int)
}) {
	.Inexact = .()
	.Filter = .()
	.Count = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesSearchCounter) () tdp.Type {
	 := tdp.Type{
		Name: "messages.searchCounter",
		ID:   MessagesSearchCounterTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Inexact",
			SchemaName: "inexact",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Filter",
			SchemaName: "filter",
		},
		{
			Name:       "Count",
			SchemaName: "count",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesSearchCounter) () {
	if !(.Inexact == false) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesSearchCounter) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.searchCounter#e844ebff as nil")
	}
	.PutID(MessagesSearchCounterTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesSearchCounter) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.searchCounter#e844ebff as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.searchCounter#e844ebff: field flags: %w", )
	}
	if .Filter == nil {
		return fmt.Errorf("unable to encode messages.searchCounter#e844ebff: field filter is nil")
	}
	if  := .Filter.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.searchCounter#e844ebff: field filter: %w", )
	}
	.PutInt(.Count)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesSearchCounter) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.searchCounter#e844ebff to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.searchCounter#e844ebff: field flags: %w", )
		}
	}
	.Inexact = .Flags.Has(1)
	{
		,  := DecodeMessagesFilter()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchCounter#e844ebff: field filter: %w", )
		}
		.Filter = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.searchCounter#e844ebff: field count: %w", )
		}
		.Count = 
	}
	return nil
}

// SetInexact sets value of Inexact conditional field.
func ( *MessagesSearchCounter) ( bool) {
	if  {
		.Flags.Set(1)
		.Inexact = true
	} else {
		.Flags.Unset(1)
		.Inexact = false
	}
}

// GetInexact returns value of Inexact conditional field.
func ( *MessagesSearchCounter) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

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

// GetCount returns value of Count field.
func ( *MessagesSearchCounter) () ( int) {
	if  == nil {
		return
	}
	return .Count
}