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

// UserWallet represents TL type `userWallet#454d2737`.
//
// See https://core.telegram.org/constructor/userWallet for reference.
type UserWallet struct {
	// Flags field of UserWallet.
	Flags bin.Fields
	// Address field of UserWallet.
	Address string
	// Balance field of UserWallet.
	Balance int64
	// PublicKey field of UserWallet.
	//
	// Use SetPublicKey and GetPublicKey helpers.
	PublicKey []byte
	// StateInit field of UserWallet.
	//
	// Use SetStateInit and GetStateInit helpers.
	StateInit []byte
}

// UserWalletTypeID is TL type id of UserWallet.
const UserWalletTypeID = 0x454d2737

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

func ( *UserWallet) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Address == "") {
		return false
	}
	if !(.Balance == 0) {
		return false
	}
	if !(.PublicKey == nil) {
		return false
	}
	if !(.StateInit == nil) {
		return false
	}

	return true
}

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

// FillFrom fills UserWallet from given interface.
func ( *UserWallet) ( interface {
	() ( string)
	() ( int64)
	() ( []byte,  bool)
	() ( []byte,  bool)
}) {
	.Address = .()
	.Balance = .()
	if ,  := .();  {
		.PublicKey = 
	}

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

}

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

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

// TypeInfo returns info about TL type.
func ( *UserWallet) () tdp.Type {
	 := tdp.Type{
		Name: "userWallet",
		ID:   UserWalletTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Address",
			SchemaName: "address",
		},
		{
			Name:       "Balance",
			SchemaName: "balance",
		},
		{
			Name:       "PublicKey",
			SchemaName: "public_key",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "StateInit",
			SchemaName: "state_init",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *UserWallet) () {
	if !(.PublicKey == nil) {
		.Flags.Set(0)
	}
	if !(.StateInit == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *UserWallet) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode userWallet#454d2737 as nil")
	}
	.PutID(UserWalletTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UserWallet) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode userWallet#454d2737 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode userWallet#454d2737: field flags: %w", )
	}
	.PutString(.Address)
	.PutLong(.Balance)
	if .Flags.Has(0) {
		.PutBytes(.PublicKey)
	}
	if .Flags.Has(0) {
		.PutBytes(.StateInit)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *UserWallet) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode userWallet#454d2737 to nil")
	}
	if  := .ConsumeID(UserWalletTypeID);  != nil {
		return fmt.Errorf("unable to decode userWallet#454d2737: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *UserWallet) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode userWallet#454d2737 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode userWallet#454d2737: field flags: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode userWallet#454d2737: field address: %w", )
		}
		.Address = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode userWallet#454d2737: field balance: %w", )
		}
		.Balance = 
	}
	if .Flags.Has(0) {
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode userWallet#454d2737: field public_key: %w", )
		}
		.PublicKey = 
	}
	if .Flags.Has(0) {
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode userWallet#454d2737: field state_init: %w", )
		}
		.StateInit = 
	}
	return nil
}

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

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

// SetPublicKey sets value of PublicKey conditional field.
func ( *UserWallet) ( []byte) {
	.Flags.Set(0)
	.PublicKey = 
}

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

// SetStateInit sets value of StateInit conditional field.
func ( *UserWallet) ( []byte) {
	.Flags.Set(0)
	.StateInit = 
}

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