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

// WalletTransactions represents TL type `wallet.transactions#4322d5a5`.
//
// See https://core.telegram.org/constructor/wallet.transactions for reference.
type WalletTransactions struct {
	// Flags field of WalletTransactions.
	Flags bin.Fields
	// Balance field of WalletTransactions.
	Balance int64
	// Transactions field of WalletTransactions.
	Transactions []WalletTransaction
	// NextOffset field of WalletTransactions.
	//
	// Use SetNextOffset and GetNextOffset helpers.
	NextOffset string
	// Chats field of WalletTransactions.
	Chats []ChatClass
	// Users field of WalletTransactions.
	Users []UserClass
}

// WalletTransactionsTypeID is TL type id of WalletTransactions.
const WalletTransactionsTypeID = 0x4322d5a5

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

func ( *WalletTransactions) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Balance == 0) {
		return false
	}
	if !(.Transactions == nil) {
		return false
	}
	if !(.NextOffset == "") {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills WalletTransactions from given interface.
func ( *WalletTransactions) ( interface {
	() ( int64)
	() ( []WalletTransaction)
	() ( string,  bool)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Balance = .()
	.Transactions = .()
	if ,  := .();  {
		.NextOffset = 
	}

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

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

// TypeName returns name of type in TL schema.
func (*WalletTransactions) () string {
	return "wallet.transactions"
}

// TypeInfo returns info about TL type.
func ( *WalletTransactions) () tdp.Type {
	 := tdp.Type{
		Name: "wallet.transactions",
		ID:   WalletTransactionsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Balance",
			SchemaName: "balance",
		},
		{
			Name:       "Transactions",
			SchemaName: "transactions",
		},
		{
			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 ( *WalletTransactions) () {
	if !(.NextOffset == "") {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *WalletTransactions) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode wallet.transactions#4322d5a5 as nil")
	}
	.PutID(WalletTransactionsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WalletTransactions) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode wallet.transactions#4322d5a5 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode wallet.transactions#4322d5a5: field flags: %w", )
	}
	.PutLong(.Balance)
	.PutVectorHeader(len(.Transactions))
	for ,  := range .Transactions {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode wallet.transactions#4322d5a5: field transactions 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 wallet.transactions#4322d5a5: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode wallet.transactions#4322d5a5: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode wallet.transactions#4322d5a5: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode wallet.transactions#4322d5a5: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *WalletTransactions) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode wallet.transactions#4322d5a5 to nil")
	}
	if  := .ConsumeID(WalletTransactionsTypeID);  != nil {
		return fmt.Errorf("unable to decode wallet.transactions#4322d5a5: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *WalletTransactions) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode wallet.transactions#4322d5a5 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode wallet.transactions#4322d5a5: field flags: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode wallet.transactions#4322d5a5: field balance: %w", )
		}
		.Balance = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode wallet.transactions#4322d5a5: field transactions: %w", )
		}

		if  > 0 {
			.Transactions = make([]WalletTransaction, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  WalletTransaction
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode wallet.transactions#4322d5a5: field transactions: %w", )
			}
			.Transactions = append(.Transactions, )
		}
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode wallet.transactions#4322d5a5: field next_offset: %w", )
		}
		.NextOffset = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode wallet.transactions#4322d5a5: field chats: %w", )
		}

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

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

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

// GetTransactions returns value of Transactions field.
func ( *WalletTransactions) () ( []WalletTransaction) {
	if  == nil {
		return
	}
	return .Transactions
}

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

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

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

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

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

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