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

// WalletTransaction represents TL type `walletTransaction#952dc143`.
//
// See https://core.telegram.org/constructor/walletTransaction for reference.
type WalletTransaction struct {
	// Flags field of WalletTransaction.
	Flags bin.Fields
	// Incoming field of WalletTransaction.
	Incoming bool
	// Gasless field of WalletTransaction.
	Gasless bool
	// Failed field of WalletTransaction.
	Failed bool
	// KeyChange field of WalletTransaction.
	KeyChange bool
	// CommentEncrypted field of WalletTransaction.
	CommentEncrypted bool
	// ID field of WalletTransaction.
	ID string
	// Amount field of WalletTransaction.
	Amount int64
	// Fee field of WalletTransaction.
	Fee int64
	// Date field of WalletTransaction.
	Date int
	// Peer field of WalletTransaction.
	Peer WalletTransactionPeerClass
	// Comment field of WalletTransaction.
	//
	// Use SetComment and GetComment helpers.
	Comment string
	// TxHash field of WalletTransaction.
	//
	// Use SetTxHash and GetTxHash helpers.
	TxHash string
	// Nft field of WalletTransaction.
	//
	// Use SetNft and GetNft helpers.
	Nft WalletNftItem
}

// WalletTransactionTypeID is TL type id of WalletTransaction.
const WalletTransactionTypeID = 0x952dc143

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

func ( *WalletTransaction) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Incoming == false) {
		return false
	}
	if !(.Gasless == false) {
		return false
	}
	if !(.Failed == false) {
		return false
	}
	if !(.KeyChange == false) {
		return false
	}
	if !(.CommentEncrypted == false) {
		return false
	}
	if !(.ID == "") {
		return false
	}
	if !(.Amount == 0) {
		return false
	}
	if !(.Fee == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Comment == "") {
		return false
	}
	if !(.TxHash == "") {
		return false
	}
	if !(.Nft.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills WalletTransaction from given interface.
func ( *WalletTransaction) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( string)
	() ( int64)
	() ( int64)
	() ( int)
	() ( WalletTransactionPeerClass)
	() ( string,  bool)
	() ( string,  bool)
	() ( WalletNftItem,  bool)
}) {
	.Incoming = .()
	.Gasless = .()
	.Failed = .()
	.KeyChange = .()
	.CommentEncrypted = .()
	.ID = .()
	.Amount = .()
	.Fee = .()
	.Date = .()
	.Peer = .()
	if ,  := .();  {
		.Comment = 
	}

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

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

}

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

// TypeName returns name of type in TL schema.
func (*WalletTransaction) () string {
	return "walletTransaction"
}

// TypeInfo returns info about TL type.
func ( *WalletTransaction) () tdp.Type {
	 := tdp.Type{
		Name: "walletTransaction",
		ID:   WalletTransactionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Incoming",
			SchemaName: "incoming",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Gasless",
			SchemaName: "gasless",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Failed",
			SchemaName: "failed",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "KeyChange",
			SchemaName: "key_change",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "CommentEncrypted",
			SchemaName: "comment_encrypted",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Amount",
			SchemaName: "amount",
		},
		{
			Name:       "Fee",
			SchemaName: "fee",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Comment",
			SchemaName: "comment",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "TxHash",
			SchemaName: "tx_hash",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "Nft",
			SchemaName: "nft",
			Null:       !.Flags.Has(7),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *WalletTransaction) () {
	if !(.Incoming == false) {
		.Flags.Set(0)
	}
	if !(.Gasless == false) {
		.Flags.Set(1)
	}
	if !(.Failed == false) {
		.Flags.Set(2)
	}
	if !(.KeyChange == false) {
		.Flags.Set(5)
	}
	if !(.CommentEncrypted == false) {
		.Flags.Set(6)
	}
	if !(.Comment == "") {
		.Flags.Set(3)
	}
	if !(.TxHash == "") {
		.Flags.Set(4)
	}
	if !(.Nft.Zero()) {
		.Flags.Set(7)
	}
}

// Encode implements bin.Encoder.
func ( *WalletTransaction) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode walletTransaction#952dc143 as nil")
	}
	.PutID(WalletTransactionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WalletTransaction) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode walletTransaction#952dc143 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode walletTransaction#952dc143: field flags: %w", )
	}
	.PutString(.ID)
	.PutLong(.Amount)
	.PutLong(.Fee)
	.PutInt(.Date)
	if .Peer == nil {
		return fmt.Errorf("unable to encode walletTransaction#952dc143: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode walletTransaction#952dc143: field peer: %w", )
	}
	if .Flags.Has(3) {
		.PutString(.Comment)
	}
	if .Flags.Has(4) {
		.PutString(.TxHash)
	}
	if .Flags.Has(7) {
		if  := .Nft.Encode();  != nil {
			return fmt.Errorf("unable to encode walletTransaction#952dc143: field nft: %w", )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *WalletTransaction) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode walletTransaction#952dc143 to nil")
	}
	if  := .ConsumeID(WalletTransactionTypeID);  != nil {
		return fmt.Errorf("unable to decode walletTransaction#952dc143: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *WalletTransaction) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode walletTransaction#952dc143 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode walletTransaction#952dc143: field flags: %w", )
		}
	}
	.Incoming = .Flags.Has(0)
	.Gasless = .Flags.Has(1)
	.Failed = .Flags.Has(2)
	.KeyChange = .Flags.Has(5)
	.CommentEncrypted = .Flags.Has(6)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode walletTransaction#952dc143: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode walletTransaction#952dc143: field amount: %w", )
		}
		.Amount = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode walletTransaction#952dc143: field fee: %w", )
		}
		.Fee = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode walletTransaction#952dc143: field date: %w", )
		}
		.Date = 
	}
	{
		,  := DecodeWalletTransactionPeer()
		if  != nil {
			return fmt.Errorf("unable to decode walletTransaction#952dc143: field peer: %w", )
		}
		.Peer = 
	}
	if .Flags.Has(3) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode walletTransaction#952dc143: field comment: %w", )
		}
		.Comment = 
	}
	if .Flags.Has(4) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode walletTransaction#952dc143: field tx_hash: %w", )
		}
		.TxHash = 
	}
	if .Flags.Has(7) {
		if  := .Nft.Decode();  != nil {
			return fmt.Errorf("unable to decode walletTransaction#952dc143: field nft: %w", )
		}
	}
	return nil
}

// SetIncoming sets value of Incoming conditional field.
func ( *WalletTransaction) ( bool) {
	if  {
		.Flags.Set(0)
		.Incoming = true
	} else {
		.Flags.Unset(0)
		.Incoming = false
	}
}

// GetIncoming returns value of Incoming conditional field.
func ( *WalletTransaction) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetGasless sets value of Gasless conditional field.
func ( *WalletTransaction) ( bool) {
	if  {
		.Flags.Set(1)
		.Gasless = true
	} else {
		.Flags.Unset(1)
		.Gasless = false
	}
}

// GetGasless returns value of Gasless conditional field.
func ( *WalletTransaction) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetFailed sets value of Failed conditional field.
func ( *WalletTransaction) ( bool) {
	if  {
		.Flags.Set(2)
		.Failed = true
	} else {
		.Flags.Unset(2)
		.Failed = false
	}
}

// GetFailed returns value of Failed conditional field.
func ( *WalletTransaction) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetKeyChange sets value of KeyChange conditional field.
func ( *WalletTransaction) ( bool) {
	if  {
		.Flags.Set(5)
		.KeyChange = true
	} else {
		.Flags.Unset(5)
		.KeyChange = false
	}
}

// GetKeyChange returns value of KeyChange conditional field.
func ( *WalletTransaction) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

// SetCommentEncrypted sets value of CommentEncrypted conditional field.
func ( *WalletTransaction) ( bool) {
	if  {
		.Flags.Set(6)
		.CommentEncrypted = true
	} else {
		.Flags.Unset(6)
		.CommentEncrypted = false
	}
}

// GetCommentEncrypted returns value of CommentEncrypted conditional field.
func ( *WalletTransaction) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(6)
}

// GetID returns value of ID field.
func ( *WalletTransaction) () ( string) {
	if  == nil {
		return
	}
	return .ID
}

// GetAmount returns value of Amount field.
func ( *WalletTransaction) () ( int64) {
	if  == nil {
		return
	}
	return .Amount
}

// GetFee returns value of Fee field.
func ( *WalletTransaction) () ( int64) {
	if  == nil {
		return
	}
	return .Fee
}

// GetDate returns value of Date field.
func ( *WalletTransaction) () ( int) {
	if  == nil {
		return
	}
	return .Date
}

// GetPeer returns value of Peer field.
func ( *WalletTransaction) () ( WalletTransactionPeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// SetComment sets value of Comment conditional field.
func ( *WalletTransaction) ( string) {
	.Flags.Set(3)
	.Comment = 
}

// GetComment returns value of Comment conditional field and
// boolean which is true if field was set.
func ( *WalletTransaction) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Comment, true
}

// SetTxHash sets value of TxHash conditional field.
func ( *WalletTransaction) ( string) {
	.Flags.Set(4)
	.TxHash = 
}

// GetTxHash returns value of TxHash conditional field and
// boolean which is true if field was set.
func ( *WalletTransaction) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .TxHash, true
}

// SetNft sets value of Nft conditional field.
func ( *WalletTransaction) ( WalletNftItem) {
	.Flags.Set(7)
	.Nft = 
}

// GetNft returns value of Nft conditional field and
// boolean which is true if field was set.
func ( *WalletTransaction) () ( WalletNftItem,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(7) {
		return , false
	}
	return .Nft, true
}