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

// PaymentsSavedInfo represents TL type `payments.savedInfo#fb8fe43c`.
// Saved server-side order information
//
// See https://core.telegram.org/constructor/payments.savedInfo for reference.
type PaymentsSavedInfo struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the user has some saved payment credentials
	HasSavedCredentials bool
	// Saved server-side order information
	//
	// Use SetSavedInfo and GetSavedInfo helpers.
	SavedInfo PaymentRequestedInfo
}

// PaymentsSavedInfoTypeID is TL type id of PaymentsSavedInfo.
const PaymentsSavedInfoTypeID = 0xfb8fe43c

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

func ( *PaymentsSavedInfo) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.HasSavedCredentials == false) {
		return false
	}
	if !(.SavedInfo.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsSavedInfo from given interface.
func ( *PaymentsSavedInfo) ( interface {
	() ( bool)
	() ( PaymentRequestedInfo,  bool)
}) {
	.HasSavedCredentials = .()
	if ,  := .();  {
		.SavedInfo = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*PaymentsSavedInfo) () string {
	return "payments.savedInfo"
}

// TypeInfo returns info about TL type.
func ( *PaymentsSavedInfo) () tdp.Type {
	 := tdp.Type{
		Name: "payments.savedInfo",
		ID:   PaymentsSavedInfoTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "HasSavedCredentials",
			SchemaName: "has_saved_credentials",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "SavedInfo",
			SchemaName: "saved_info",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PaymentsSavedInfo) () {
	if !(.HasSavedCredentials == false) {
		.Flags.Set(1)
	}
	if !(.SavedInfo.Zero()) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *PaymentsSavedInfo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.savedInfo#fb8fe43c as nil")
	}
	.PutID(PaymentsSavedInfoTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsSavedInfo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.savedInfo#fb8fe43c as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.savedInfo#fb8fe43c: field flags: %w", )
	}
	if .Flags.Has(0) {
		if  := .SavedInfo.Encode();  != nil {
			return fmt.Errorf("unable to encode payments.savedInfo#fb8fe43c: field saved_info: %w", )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *PaymentsSavedInfo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.savedInfo#fb8fe43c to nil")
	}
	if  := .ConsumeID(PaymentsSavedInfoTypeID);  != nil {
		return fmt.Errorf("unable to decode payments.savedInfo#fb8fe43c: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsSavedInfo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.savedInfo#fb8fe43c to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.savedInfo#fb8fe43c: field flags: %w", )
		}
	}
	.HasSavedCredentials = .Flags.Has(1)
	if .Flags.Has(0) {
		if  := .SavedInfo.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.savedInfo#fb8fe43c: field saved_info: %w", )
		}
	}
	return nil
}

// SetHasSavedCredentials sets value of HasSavedCredentials conditional field.
func ( *PaymentsSavedInfo) ( bool) {
	if  {
		.Flags.Set(1)
		.HasSavedCredentials = true
	} else {
		.Flags.Unset(1)
		.HasSavedCredentials = false
	}
}

// GetHasSavedCredentials returns value of HasSavedCredentials conditional field.
func ( *PaymentsSavedInfo) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetSavedInfo sets value of SavedInfo conditional field.
func ( *PaymentsSavedInfo) ( PaymentRequestedInfo) {
	.Flags.Set(0)
	.SavedInfo = 
}

// GetSavedInfo returns value of SavedInfo conditional field and
// boolean which is true if field was set.
func ( *PaymentsSavedInfo) () ( PaymentRequestedInfo,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .SavedInfo, true
}