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

// PaymentsStarsStatus represents TL type `payments.starsStatus#6c9ce8ed`.
// Info about the current Telegram Star subscriptions, balance and transaction history
// »¹.
//
// Links:
//  1. https://core.telegram.org/api/stars#balance-and-transaction-history
//
// See https://core.telegram.org/constructor/payments.starsStatus for reference.
type PaymentsStarsStatus struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Current Telegram Star balance.
	Balance StarsAmountClass
	// Info about current Telegram Star subscriptions, only returned when invoking payments
	// getStarsTransactions¹ and payments.getStarsSubscriptions².
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getStarsTransactions
	//  2) https://core.telegram.org/method/payments.getStarsSubscriptions
	//
	// Use SetSubscriptions and GetSubscriptions helpers.
	Subscriptions []StarsSubscription
	// Offset for pagination of subscriptions: only usable and returned when invoking
	// payments.getStarsSubscriptions¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getStarsSubscriptions
	//
	// Use SetSubscriptionsNextOffset and GetSubscriptionsNextOffset helpers.
	SubscriptionsNextOffset string
	// The number of Telegram Stars the user should buy to be able to extend expired
	// subscriptions soon (i.e. the current balance is not enough to extend all expired
	// subscriptions).
	//
	// Use SetSubscriptionsMissingBalance and GetSubscriptionsMissingBalance helpers.
	SubscriptionsMissingBalance int64
	// List of Telegram Star transactions (partial if next_offset is set).
	//
	// Use SetHistory and GetHistory helpers.
	History []StarsTransaction
	// Offset to use to fetch more transactions from the transaction history using payments
	// getStarsTransactions¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getStarsTransactions
	//
	// Use SetNextOffset and GetNextOffset helpers.
	NextOffset string
	// Chats mentioned in history.
	Chats []ChatClass
	// Users mentioned in history.
	Users []UserClass
}

// PaymentsStarsStatusTypeID is TL type id of PaymentsStarsStatus.
const PaymentsStarsStatusTypeID = 0x6c9ce8ed

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

func ( *PaymentsStarsStatus) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Balance == nil) {
		return false
	}
	if !(.Subscriptions == nil) {
		return false
	}
	if !(.SubscriptionsNextOffset == "") {
		return false
	}
	if !(.SubscriptionsMissingBalance == 0) {
		return false
	}
	if !(.History == nil) {
		return false
	}
	if !(.NextOffset == "") {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsStarsStatus from given interface.
func ( *PaymentsStarsStatus) ( interface {
	() ( StarsAmountClass)
	() ( []StarsSubscription,  bool)
	() ( string,  bool)
	() ( int64,  bool)
	() ( []StarsTransaction,  bool)
	() ( string,  bool)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Balance = .()
	if ,  := .();  {
		.Subscriptions = 
	}

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

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

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

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

	.Chats = .()
	.Users = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsStarsStatus) () tdp.Type {
	 := tdp.Type{
		Name: "payments.starsStatus",
		ID:   PaymentsStarsStatusTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Balance",
			SchemaName: "balance",
		},
		{
			Name:       "Subscriptions",
			SchemaName: "subscriptions",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "SubscriptionsNextOffset",
			SchemaName: "subscriptions_next_offset",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "SubscriptionsMissingBalance",
			SchemaName: "subscriptions_missing_balance",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "History",
			SchemaName: "history",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "NextOffset",
			SchemaName: "next_offset",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PaymentsStarsStatus) () {
	if !(.Subscriptions == nil) {
		.Flags.Set(1)
	}
	if !(.SubscriptionsNextOffset == "") {
		.Flags.Set(2)
	}
	if !(.SubscriptionsMissingBalance == 0) {
		.Flags.Set(4)
	}
	if !(.History == nil) {
		.Flags.Set(3)
	}
	if !(.NextOffset == "") {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *PaymentsStarsStatus) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.starsStatus#6c9ce8ed as nil")
	}
	.PutID(PaymentsStarsStatusTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsStarsStatus) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.starsStatus#6c9ce8ed as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.starsStatus#6c9ce8ed: field flags: %w", )
	}
	if .Balance == nil {
		return fmt.Errorf("unable to encode payments.starsStatus#6c9ce8ed: field balance is nil")
	}
	if  := .Balance.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.starsStatus#6c9ce8ed: field balance: %w", )
	}
	if .Flags.Has(1) {
		.PutVectorHeader(len(.Subscriptions))
		for ,  := range .Subscriptions {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode payments.starsStatus#6c9ce8ed: field subscriptions element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(2) {
		.PutString(.SubscriptionsNextOffset)
	}
	if .Flags.Has(4) {
		.PutLong(.SubscriptionsMissingBalance)
	}
	if .Flags.Has(3) {
		.PutVectorHeader(len(.History))
		for ,  := range .History {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode payments.starsStatus#6c9ce8ed: field history element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(0) {
		.PutString(.NextOffset)
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode payments.starsStatus#6c9ce8ed: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.starsStatus#6c9ce8ed: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode payments.starsStatus#6c9ce8ed: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.starsStatus#6c9ce8ed: field users element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsStarsStatus) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.starsStatus#6c9ce8ed to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field flags: %w", )
		}
	}
	{
		,  := DecodeStarsAmount()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field balance: %w", )
		}
		.Balance = 
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field subscriptions: %w", )
		}

		if  > 0 {
			.Subscriptions = make([]StarsSubscription, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  StarsSubscription
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field subscriptions: %w", )
			}
			.Subscriptions = append(.Subscriptions, )
		}
	}
	if .Flags.Has(2) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field subscriptions_next_offset: %w", )
		}
		.SubscriptionsNextOffset = 
	}
	if .Flags.Has(4) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field subscriptions_missing_balance: %w", )
		}
		.SubscriptionsMissingBalance = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field history: %w", )
		}

		if  > 0 {
			.History = make([]StarsTransaction, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  StarsTransaction
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field history: %w", )
			}
			.History = append(.History, )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field next_offset: %w", )
		}
		.NextOffset = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field chats: %w", )
		}

		if  > 0 {
			.Chats = make([]ChatClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChat()
			if  != nil {
				return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field chats: %w", )
			}
			.Chats = append(.Chats, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starsStatus#6c9ce8ed: field users: %w", )
		}

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

// GetBalance returns value of Balance field.
func ( *PaymentsStarsStatus) () ( StarsAmountClass) {
	if  == nil {
		return
	}
	return .Balance
}

// SetSubscriptions sets value of Subscriptions conditional field.
func ( *PaymentsStarsStatus) ( []StarsSubscription) {
	.Flags.Set(1)
	.Subscriptions = 
}

// GetSubscriptions returns value of Subscriptions conditional field and
// boolean which is true if field was set.
func ( *PaymentsStarsStatus) () ( []StarsSubscription,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Subscriptions, true
}

// SetSubscriptionsNextOffset sets value of SubscriptionsNextOffset conditional field.
func ( *PaymentsStarsStatus) ( string) {
	.Flags.Set(2)
	.SubscriptionsNextOffset = 
}

// GetSubscriptionsNextOffset returns value of SubscriptionsNextOffset conditional field and
// boolean which is true if field was set.
func ( *PaymentsStarsStatus) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .SubscriptionsNextOffset, true
}

// SetSubscriptionsMissingBalance sets value of SubscriptionsMissingBalance conditional field.
func ( *PaymentsStarsStatus) ( int64) {
	.Flags.Set(4)
	.SubscriptionsMissingBalance = 
}

// GetSubscriptionsMissingBalance returns value of SubscriptionsMissingBalance conditional field and
// boolean which is true if field was set.
func ( *PaymentsStarsStatus) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .SubscriptionsMissingBalance, true
}

// SetHistory sets value of History conditional field.
func ( *PaymentsStarsStatus) ( []StarsTransaction) {
	.Flags.Set(3)
	.History = 
}

// GetHistory returns value of History conditional field and
// boolean which is true if field was set.
func ( *PaymentsStarsStatus) () ( []StarsTransaction,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .History, true
}

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

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

// GetChats returns value of Chats field.
func ( *PaymentsStarsStatus) () ( []ChatClass) {
	if  == nil {
		return
	}
	return .Chats
}

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

// MapChats returns field Chats wrapped in ChatClassArray helper.
func ( *PaymentsStarsStatus) () ( ChatClassArray) {
	return ChatClassArray(.Chats)
}

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