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

// PaymentsSuggestedStarRefBots represents TL type `payments.suggestedStarRefBots#b4d5d859`.
// A list of suggested mini apps¹ with available affiliate programs²
//
// Links:
//  1. https://core.telegram.org/api/bots/webapps
//  2. https://core.telegram.org/api/bots/referrals
//
// See https://core.telegram.org/constructor/payments.suggestedStarRefBots for reference.
type PaymentsSuggestedStarRefBots struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Total number of results (for pagination)
	Count int
	// Suggested affiliate programs (full or partial list to be fetched using pagination)
	SuggestedBots []StarRefProgram
	// Peers mentioned in suggested_bots
	Users []UserClass
	// Next offset for pagination¹
	//
	// Links:
	//  1) https://core.telegram.org/api/offsets
	//
	// Use SetNextOffset and GetNextOffset helpers.
	NextOffset string
}

// PaymentsSuggestedStarRefBotsTypeID is TL type id of PaymentsSuggestedStarRefBots.
const PaymentsSuggestedStarRefBotsTypeID = 0xb4d5d859

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

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

	return true
}

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

// FillFrom fills PaymentsSuggestedStarRefBots from given interface.
func ( *PaymentsSuggestedStarRefBots) ( interface {
	() ( int)
	() ( []StarRefProgram)
	() ( []UserClass)
	() ( string,  bool)
}) {
	.Count = .()
	.SuggestedBots = .()
	.Users = .()
	if ,  := .();  {
		.NextOffset = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*PaymentsSuggestedStarRefBots) () string {
	return "payments.suggestedStarRefBots"
}

// TypeInfo returns info about TL type.
func ( *PaymentsSuggestedStarRefBots) () tdp.Type {
	 := tdp.Type{
		Name: "payments.suggestedStarRefBots",
		ID:   PaymentsSuggestedStarRefBotsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Count",
			SchemaName: "count",
		},
		{
			Name:       "SuggestedBots",
			SchemaName: "suggested_bots",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
		{
			Name:       "NextOffset",
			SchemaName: "next_offset",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *PaymentsSuggestedStarRefBots) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.suggestedStarRefBots#b4d5d859 as nil")
	}
	.PutID(PaymentsSuggestedStarRefBotsTypeID)
	return .EncodeBare()
}

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

// Decode implements bin.Decoder.
func ( *PaymentsSuggestedStarRefBots) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.suggestedStarRefBots#b4d5d859 to nil")
	}
	if  := .ConsumeID(PaymentsSuggestedStarRefBotsTypeID);  != nil {
		return fmt.Errorf("unable to decode payments.suggestedStarRefBots#b4d5d859: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsSuggestedStarRefBots) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.suggestedStarRefBots#b4d5d859 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.suggestedStarRefBots#b4d5d859: field flags: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.suggestedStarRefBots#b4d5d859: field count: %w", )
		}
		.Count = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.suggestedStarRefBots#b4d5d859: field suggested_bots: %w", )
		}

		if  > 0 {
			.SuggestedBots = make([]StarRefProgram, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  StarRefProgram
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode payments.suggestedStarRefBots#b4d5d859: field suggested_bots: %w", )
			}
			.SuggestedBots = append(.SuggestedBots, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.suggestedStarRefBots#b4d5d859: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode payments.suggestedStarRefBots#b4d5d859: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.suggestedStarRefBots#b4d5d859: field next_offset: %w", )
		}
		.NextOffset = 
	}
	return nil
}

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

// GetSuggestedBots returns value of SuggestedBots field.
func ( *PaymentsSuggestedStarRefBots) () ( []StarRefProgram) {
	if  == nil {
		return
	}
	return .SuggestedBots
}

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

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

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

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