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

// WalletStateEmpty represents TL type `walletStateEmpty#9cb9b2ec`.
//
// See https://core.telegram.org/constructor/walletStateEmpty for reference.
type WalletStateEmpty struct {
	// Flags field of WalletStateEmpty.
	Flags bin.Fields
	// Creating field of WalletStateEmpty.
	Creating bool
}

// WalletStateEmptyTypeID is TL type id of WalletStateEmpty.
const WalletStateEmptyTypeID = 0x9cb9b2ec

// construct implements constructor of WalletStateClass.
func ( WalletStateEmpty) () WalletStateClass { return & }

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

	_ WalletStateClass = &WalletStateEmpty{}
)

func ( *WalletStateEmpty) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Creating == false) {
		return false
	}

	return true
}

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

// FillFrom fills WalletStateEmpty from given interface.
func ( *WalletStateEmpty) ( interface {
	() ( bool)
}) {
	.Creating = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *WalletStateEmpty) () tdp.Type {
	 := tdp.Type{
		Name: "walletStateEmpty",
		ID:   WalletStateEmptyTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Creating",
			SchemaName: "creating",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *WalletStateEmpty) () {
	if !(.Creating == false) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *WalletStateEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode walletStateEmpty#9cb9b2ec as nil")
	}
	.PutID(WalletStateEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WalletStateEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode walletStateEmpty#9cb9b2ec as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode walletStateEmpty#9cb9b2ec: field flags: %w", )
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *WalletStateEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode walletStateEmpty#9cb9b2ec to nil")
	}
	if  := .ConsumeID(WalletStateEmptyTypeID);  != nil {
		return fmt.Errorf("unable to decode walletStateEmpty#9cb9b2ec: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *WalletStateEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode walletStateEmpty#9cb9b2ec to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode walletStateEmpty#9cb9b2ec: field flags: %w", )
		}
	}
	.Creating = .Flags.Has(0)
	return nil
}

// SetCreating sets value of Creating conditional field.
func ( *WalletStateEmpty) ( bool) {
	if  {
		.Flags.Set(0)
		.Creating = true
	} else {
		.Flags.Unset(0)
		.Creating = false
	}
}

// GetCreating returns value of Creating conditional field.
func ( *WalletStateEmpty) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// WalletState represents TL type `walletState#95c5346b`.
//
// See https://core.telegram.org/constructor/walletState for reference.
type WalletState struct {
	// Flags field of WalletState.
	Flags bin.Fields
	// BackupEnabled field of WalletState.
	BackupEnabled bool
	// CanExportPhrase field of WalletState.
	CanExportPhrase bool
	// CanEnableBackup field of WalletState.
	CanEnableBackup bool
	// Address field of WalletState.
	Address string
	// PublicKey field of WalletState.
	PublicKey []byte
	// Balance field of WalletState.
	Balance int64
}

// WalletStateTypeID is TL type id of WalletState.
const WalletStateTypeID = 0x95c5346b

// construct implements constructor of WalletStateClass.
func ( WalletState) () WalletStateClass { return & }

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

	_ WalletStateClass = &WalletState{}
)

func ( *WalletState) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.BackupEnabled == false) {
		return false
	}
	if !(.CanExportPhrase == false) {
		return false
	}
	if !(.CanEnableBackup == false) {
		return false
	}
	if !(.Address == "") {
		return false
	}
	if !(.PublicKey == nil) {
		return false
	}
	if !(.Balance == 0) {
		return false
	}

	return true
}

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

// FillFrom fills WalletState from given interface.
func ( *WalletState) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( string)
	() ( []byte)
	() ( int64)
}) {
	.BackupEnabled = .()
	.CanExportPhrase = .()
	.CanEnableBackup = .()
	.Address = .()
	.PublicKey = .()
	.Balance = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *WalletState) () tdp.Type {
	 := tdp.Type{
		Name: "walletState",
		ID:   WalletStateTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "BackupEnabled",
			SchemaName: "backup_enabled",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "CanExportPhrase",
			SchemaName: "can_export_phrase",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "CanEnableBackup",
			SchemaName: "can_enable_backup",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Address",
			SchemaName: "address",
		},
		{
			Name:       "PublicKey",
			SchemaName: "public_key",
		},
		{
			Name:       "Balance",
			SchemaName: "balance",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *WalletState) () {
	if !(.BackupEnabled == false) {
		.Flags.Set(0)
	}
	if !(.CanExportPhrase == false) {
		.Flags.Set(1)
	}
	if !(.CanEnableBackup == false) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *WalletState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode walletState#95c5346b as nil")
	}
	.PutID(WalletStateTypeID)
	return .EncodeBare()
}

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

// Decode implements bin.Decoder.
func ( *WalletState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode walletState#95c5346b to nil")
	}
	if  := .ConsumeID(WalletStateTypeID);  != nil {
		return fmt.Errorf("unable to decode walletState#95c5346b: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *WalletState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode walletState#95c5346b to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode walletState#95c5346b: field flags: %w", )
		}
	}
	.BackupEnabled = .Flags.Has(0)
	.CanExportPhrase = .Flags.Has(1)
	.CanEnableBackup = .Flags.Has(2)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode walletState#95c5346b: field address: %w", )
		}
		.Address = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode walletState#95c5346b: field public_key: %w", )
		}
		.PublicKey = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode walletState#95c5346b: field balance: %w", )
		}
		.Balance = 
	}
	return nil
}

// SetBackupEnabled sets value of BackupEnabled conditional field.
func ( *WalletState) ( bool) {
	if  {
		.Flags.Set(0)
		.BackupEnabled = true
	} else {
		.Flags.Unset(0)
		.BackupEnabled = false
	}
}

// GetBackupEnabled returns value of BackupEnabled conditional field.
func ( *WalletState) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetCanExportPhrase sets value of CanExportPhrase conditional field.
func ( *WalletState) ( bool) {
	if  {
		.Flags.Set(1)
		.CanExportPhrase = true
	} else {
		.Flags.Unset(1)
		.CanExportPhrase = false
	}
}

// GetCanExportPhrase returns value of CanExportPhrase conditional field.
func ( *WalletState) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetCanEnableBackup sets value of CanEnableBackup conditional field.
func ( *WalletState) ( bool) {
	if  {
		.Flags.Set(2)
		.CanEnableBackup = true
	} else {
		.Flags.Unset(2)
		.CanEnableBackup = false
	}
}

// GetCanEnableBackup returns value of CanEnableBackup conditional field.
func ( *WalletState) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

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

// GetPublicKey returns value of PublicKey field.
func ( *WalletState) () ( []byte) {
	if  == nil {
		return
	}
	return .PublicKey
}

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

// WalletStateClassName is schema name of WalletStateClass.
const WalletStateClassName = "WalletState"

// WalletStateClass represents WalletState generic type.
//
// See https://core.telegram.org/type/WalletState for reference.
//
// Constructors:
//   - [WalletStateEmpty]
//   - [WalletState]
//
// Example:
//
//	g, err := tg.DecodeWalletState(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.WalletStateEmpty: // walletStateEmpty#9cb9b2ec
//	case *tg.WalletState: // walletState#95c5346b
//	default: panic(v)
//	}
type WalletStateClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() WalletStateClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// AsNotEmpty tries to map WalletStateClass to WalletState.
	AsNotEmpty() (*WalletState, bool)
}

// AsNotEmpty tries to map WalletStateEmpty to WalletState.
func ( *WalletStateEmpty) () (*WalletState, bool) {
	return nil, false
}

// AsNotEmpty tries to map WalletState to WalletState.
func ( *WalletState) () (*WalletState, bool) {
	return , true
}

// DecodeWalletState implements binary de-serialization for WalletStateClass.
func ( *bin.Buffer) (WalletStateClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case WalletStateEmptyTypeID:
		// Decoding walletStateEmpty#9cb9b2ec.
		 := WalletStateEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode WalletStateClass: %w", )
		}
		return &, nil
	case WalletStateTypeID:
		// Decoding walletState#95c5346b.
		 := WalletState{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode WalletStateClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode WalletStateClass: %w", bin.NewUnexpectedID())
	}
}

// WalletState boxes the WalletStateClass providing a helper.
type WalletStateBox struct {
	WalletState WalletStateClass
}

// Decode implements bin.Decoder for WalletStateBox.
func ( *WalletStateBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode WalletStateBox to nil")
	}
	,  := DecodeWalletState()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.WalletState = 
	return nil
}

// Encode implements bin.Encode for WalletStateBox.
func ( *WalletStateBox) ( *bin.Buffer) error {
	if  == nil || .WalletState == nil {
		return fmt.Errorf("unable to encode WalletStateClass as nil")
	}
	return .WalletState.Encode()
}