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

// BotsPopularAppBots represents TL type `bots.popularAppBots#1991b13b`.
// Popular Main Mini Apps¹, to be used in the apps tab of global search »².
//
// Links:
//  1. https://core.telegram.org/api/bots/webapps#main-mini-apps
//  2. https://core.telegram.org/api/search#apps-tab
//
// See https://core.telegram.org/constructor/bots.popularAppBots for reference.
type BotsPopularAppBots struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Offset for pagination¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	//
	// Use SetNextOffset and GetNextOffset helpers.
	NextOffset string
	// The bots associated to each Main Mini App, see here »¹ for more info.
	//
	// Links:
	//  1) https://core.telegram.org/api/bots/webapps#main-mini-apps
	Users []UserClass
}

// BotsPopularAppBotsTypeID is TL type id of BotsPopularAppBots.
const BotsPopularAppBotsTypeID = 0x1991b13b

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

func ( *BotsPopularAppBots) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.NextOffset == "") {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills BotsPopularAppBots from given interface.
func ( *BotsPopularAppBots) ( interface {
	() ( string,  bool)
	() ( []UserClass)
}) {
	if ,  := .();  {
		.NextOffset = 
	}

	.Users = .()
}

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

// TypeName returns name of type in TL schema.
func (*BotsPopularAppBots) () string {
	return "bots.popularAppBots"
}

// TypeInfo returns info about TL type.
func ( *BotsPopularAppBots) () tdp.Type {
	 := tdp.Type{
		Name: "bots.popularAppBots",
		ID:   BotsPopularAppBotsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "NextOffset",
			SchemaName: "next_offset",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *BotsPopularAppBots) () {
	if !(.NextOffset == "") {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *BotsPopularAppBots) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode bots.popularAppBots#1991b13b as nil")
	}
	.PutID(BotsPopularAppBotsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *BotsPopularAppBots) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode bots.popularAppBots#1991b13b as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode bots.popularAppBots#1991b13b: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutString(.NextOffset)
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode bots.popularAppBots#1991b13b: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode bots.popularAppBots#1991b13b: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *BotsPopularAppBots) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode bots.popularAppBots#1991b13b to nil")
	}
	if  := .ConsumeID(BotsPopularAppBotsTypeID);  != nil {
		return fmt.Errorf("unable to decode bots.popularAppBots#1991b13b: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *BotsPopularAppBots) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode bots.popularAppBots#1991b13b to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode bots.popularAppBots#1991b13b: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode bots.popularAppBots#1991b13b: field next_offset: %w", )
		}
		.NextOffset = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode bots.popularAppBots#1991b13b: field users: %w", )
		}

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

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

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

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

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