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

// MessagesBotResults represents TL type `messages.botResults#e021f2f6`.
// Result of a query to an inline bot
//
// See https://core.telegram.org/constructor/messages.botResults for reference.
type MessagesBotResults struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the result is a picture gallery
	Gallery bool
	// Query ID
	QueryID int64
	// The next offset to use when navigating through results
	//
	// Use SetNextOffset and GetNextOffset helpers.
	NextOffset string
	// Shown as a button on top of the remaining inline result list; if clicked, redirects
	// the user to a private chat with the bot with the specified start parameter.
	//
	// Use SetSwitchPm and GetSwitchPm helpers.
	SwitchPm InlineBotSwitchPM
	// Shown as a button on top of the remaining inline result list; if clicked, opens the
	// specified inline mode mini appĀ¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/bots/webapps#inline-mode-mini-apps
	//
	// Use SetSwitchWebview and GetSwitchWebview helpers.
	SwitchWebview InlineBotWebView
	// The results
	Results []BotInlineResultClass
	// Caching validity of the results
	CacheTime int
	// Users mentioned in the results
	Users []UserClass
}

// MessagesBotResultsTypeID is TL type id of MessagesBotResults.
const MessagesBotResultsTypeID = 0xe021f2f6

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

func ( *MessagesBotResults) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Gallery == false) {
		return false
	}
	if !(.QueryID == 0) {
		return false
	}
	if !(.NextOffset == "") {
		return false
	}
	if !(.SwitchPm.Zero()) {
		return false
	}
	if !(.SwitchWebview.Zero()) {
		return false
	}
	if !(.Results == nil) {
		return false
	}
	if !(.CacheTime == 0) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesBotResults from given interface.
func ( *MessagesBotResults) ( interface {
	() ( bool)
	() ( int64)
	() ( string,  bool)
	() ( InlineBotSwitchPM,  bool)
	() ( InlineBotWebView,  bool)
	() ( []BotInlineResultClass)
	() ( int)
	() ( []UserClass)
}) {
	.Gallery = .()
	.QueryID = .()
	if ,  := .();  {
		.NextOffset = 
	}

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

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

	.Results = .()
	.CacheTime = .()
	.Users = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesBotResults) () tdp.Type {
	 := tdp.Type{
		Name: "messages.botResults",
		ID:   MessagesBotResultsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Gallery",
			SchemaName: "gallery",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "QueryID",
			SchemaName: "query_id",
		},
		{
			Name:       "NextOffset",
			SchemaName: "next_offset",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "SwitchPm",
			SchemaName: "switch_pm",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "SwitchWebview",
			SchemaName: "switch_webview",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Results",
			SchemaName: "results",
		},
		{
			Name:       "CacheTime",
			SchemaName: "cache_time",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesBotResults) () {
	if !(.Gallery == false) {
		.Flags.Set(0)
	}
	if !(.NextOffset == "") {
		.Flags.Set(1)
	}
	if !(.SwitchPm.Zero()) {
		.Flags.Set(2)
	}
	if !(.SwitchWebview.Zero()) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesBotResults) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.botResults#e021f2f6 as nil")
	}
	.PutID(MessagesBotResultsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesBotResults) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.botResults#e021f2f6 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.botResults#e021f2f6: field flags: %w", )
	}
	.PutLong(.QueryID)
	if .Flags.Has(1) {
		.PutString(.NextOffset)
	}
	if .Flags.Has(2) {
		if  := .SwitchPm.Encode();  != nil {
			return fmt.Errorf("unable to encode messages.botResults#e021f2f6: field switch_pm: %w", )
		}
	}
	if .Flags.Has(3) {
		if  := .SwitchWebview.Encode();  != nil {
			return fmt.Errorf("unable to encode messages.botResults#e021f2f6: field switch_webview: %w", )
		}
	}
	.PutVectorHeader(len(.Results))
	for ,  := range .Results {
		if  == nil {
			return fmt.Errorf("unable to encode messages.botResults#e021f2f6: field results element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.botResults#e021f2f6: field results element with index %d: %w", , )
		}
	}
	.PutInt(.CacheTime)
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode messages.botResults#e021f2f6: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.botResults#e021f2f6: field users element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesBotResults) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.botResults#e021f2f6 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field flags: %w", )
		}
	}
	.Gallery = .Flags.Has(0)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field query_id: %w", )
		}
		.QueryID = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field next_offset: %w", )
		}
		.NextOffset = 
	}
	if .Flags.Has(2) {
		if  := .SwitchPm.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field switch_pm: %w", )
		}
	}
	if .Flags.Has(3) {
		if  := .SwitchWebview.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field switch_webview: %w", )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field results: %w", )
		}

		if  > 0 {
			.Results = make([]BotInlineResultClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeBotInlineResult()
			if  != nil {
				return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field results: %w", )
			}
			.Results = append(.Results, )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field cache_time: %w", )
		}
		.CacheTime = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode messages.botResults#e021f2f6: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	return nil
}

// SetGallery sets value of Gallery conditional field.
func ( *MessagesBotResults) ( bool) {
	if  {
		.Flags.Set(0)
		.Gallery = true
	} else {
		.Flags.Unset(0)
		.Gallery = false
	}
}

// GetGallery returns value of Gallery conditional field.
func ( *MessagesBotResults) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetQueryID returns value of QueryID field.
func ( *MessagesBotResults) () ( int64) {
	if  == nil {
		return
	}
	return .QueryID
}

// SetNextOffset sets value of NextOffset conditional field.
func ( *MessagesBotResults) ( string) {
	.Flags.Set(1)
	.NextOffset = 
}

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

// SetSwitchPm sets value of SwitchPm conditional field.
func ( *MessagesBotResults) ( InlineBotSwitchPM) {
	.Flags.Set(2)
	.SwitchPm = 
}

// GetSwitchPm returns value of SwitchPm conditional field and
// boolean which is true if field was set.
func ( *MessagesBotResults) () ( InlineBotSwitchPM,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .SwitchPm, true
}

// SetSwitchWebview sets value of SwitchWebview conditional field.
func ( *MessagesBotResults) ( InlineBotWebView) {
	.Flags.Set(3)
	.SwitchWebview = 
}

// GetSwitchWebview returns value of SwitchWebview conditional field and
// boolean which is true if field was set.
func ( *MessagesBotResults) () ( InlineBotWebView,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .SwitchWebview, true
}

// GetResults returns value of Results field.
func ( *MessagesBotResults) () ( []BotInlineResultClass) {
	if  == nil {
		return
	}
	return .Results
}

// GetCacheTime returns value of CacheTime field.
func ( *MessagesBotResults) () ( int) {
	if  == nil {
		return
	}
	return .CacheTime
}

// GetUsers returns value of Users field.
func ( *MessagesBotResults) () ( []UserClass) {
	if  == nil {
		return
	}
	return .Users
}

// MapResults returns field Results wrapped in BotInlineResultClassArray helper.
func ( *MessagesBotResults) () ( BotInlineResultClassArray) {
	return BotInlineResultClassArray(.Results)
}

// MapUsers returns field Users wrapped in UserClassArray helper.
func ( *MessagesBotResults) () ( UserClassArray) {
	return UserClassArray(.Users)
}