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

// WalletCard represents TL type `wallet.card#8ed043b1`.
//
// See https://core.telegram.org/constructor/wallet.card for reference.
type WalletCard struct {
	// Flags field of WalletCard.
	Flags bin.Fields
	// Stickers field of WalletCard.
	//
	// Use SetStickers and GetStickers helpers.
	Stickers []WalletCardSticker
	// BgNftItem field of WalletCard.
	//
	// Use SetBgNftItem and GetBgNftItem helpers.
	BgNftItem WalletNftItem
	// Address field of WalletCard.
	Address string
	// Balance field of WalletCard.
	Balance int64
}

// WalletCardTypeID is TL type id of WalletCard.
const WalletCardTypeID = 0x8ed043b1

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

func ( *WalletCard) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Stickers == nil) {
		return false
	}
	if !(.BgNftItem.Zero()) {
		return false
	}
	if !(.Address == "") {
		return false
	}
	if !(.Balance == 0) {
		return false
	}

	return true
}

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

// FillFrom fills WalletCard from given interface.
func ( *WalletCard) ( interface {
	() ( []WalletCardSticker,  bool)
	() ( WalletNftItem,  bool)
	() ( string)
	() ( int64)
}) {
	if ,  := .();  {
		.Stickers = 
	}

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

	.Address = .()
	.Balance = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *WalletCard) () tdp.Type {
	 := tdp.Type{
		Name: "wallet.card",
		ID:   WalletCardTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Stickers",
			SchemaName: "stickers",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "BgNftItem",
			SchemaName: "bg_nft_item",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Address",
			SchemaName: "address",
		},
		{
			Name:       "Balance",
			SchemaName: "balance",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *WalletCard) () {
	if !(.Stickers == nil) {
		.Flags.Set(0)
	}
	if !(.BgNftItem.Zero()) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *WalletCard) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode wallet.card#8ed043b1 as nil")
	}
	.PutID(WalletCardTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WalletCard) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode wallet.card#8ed043b1 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode wallet.card#8ed043b1: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutVectorHeader(len(.Stickers))
		for ,  := range .Stickers {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode wallet.card#8ed043b1: field stickers element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(1) {
		if  := .BgNftItem.Encode();  != nil {
			return fmt.Errorf("unable to encode wallet.card#8ed043b1: field bg_nft_item: %w", )
		}
	}
	.PutString(.Address)
	.PutLong(.Balance)
	return nil
}

// Decode implements bin.Decoder.
func ( *WalletCard) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode wallet.card#8ed043b1 to nil")
	}
	if  := .ConsumeID(WalletCardTypeID);  != nil {
		return fmt.Errorf("unable to decode wallet.card#8ed043b1: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *WalletCard) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode wallet.card#8ed043b1 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode wallet.card#8ed043b1: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode wallet.card#8ed043b1: field stickers: %w", )
		}

		if  > 0 {
			.Stickers = make([]WalletCardSticker, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  WalletCardSticker
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode wallet.card#8ed043b1: field stickers: %w", )
			}
			.Stickers = append(.Stickers, )
		}
	}
	if .Flags.Has(1) {
		if  := .BgNftItem.Decode();  != nil {
			return fmt.Errorf("unable to decode wallet.card#8ed043b1: field bg_nft_item: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode wallet.card#8ed043b1: field address: %w", )
		}
		.Address = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode wallet.card#8ed043b1: field balance: %w", )
		}
		.Balance = 
	}
	return nil
}

// SetStickers sets value of Stickers conditional field.
func ( *WalletCard) ( []WalletCardSticker) {
	.Flags.Set(0)
	.Stickers = 
}

// GetStickers returns value of Stickers conditional field and
// boolean which is true if field was set.
func ( *WalletCard) () ( []WalletCardSticker,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Stickers, true
}

// SetBgNftItem sets value of BgNftItem conditional field.
func ( *WalletCard) ( WalletNftItem) {
	.Flags.Set(1)
	.BgNftItem = 
}

// GetBgNftItem returns value of BgNftItem conditional field and
// boolean which is true if field was set.
func ( *WalletCard) () ( WalletNftItem,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .BgNftItem, true
}

// GetAddress returns value of Address field.
func ( *WalletCard) () ( string) {
	if  == nil {
		return
	}
	return .Address
}

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