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

// PaymentsPaymentForm represents TL type `payments.paymentForm#a0058751`.
// Payment form
//
// See https://core.telegram.org/constructor/payments.paymentForm for reference.
type PaymentsPaymentForm struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the user can choose to save credentials.
	CanSaveCredentials bool
	// Indicates that the user can save payment credentials, but only after setting up a 2FA
	// password¹ (currently the account doesn't have a 2FA password²)
	//
	// Links:
	//  1) https://core.telegram.org/api/srp
	//  2) https://core.telegram.org/api/srp
	PasswordMissing bool
	// Form ID
	FormID int64
	// Bot ID
	BotID int64
	// Form title
	Title string
	// Description
	Description string
	// Product photo
	//
	// Use SetPhoto and GetPhoto helpers.
	Photo WebDocumentClass
	// Invoice
	Invoice Invoice
	// Payment provider ID.
	ProviderID int64
	// Payment form URL
	URL string
	// Payment provider name.One of the following:- stripe
	//
	// Use SetNativeProvider and GetNativeProvider helpers.
	NativeProvider string
	// Contains information about the payment provider, if available, to support it natively
	// without the need for opening the URL.A JSON object that can contain the following
	// fields:- apple_pay_merchant_id: Apple Pay merchant ID- google_pay_public_key: Google
	// Pay public key- need_country: True, if the user country must be provided,- need_zip:
	// True, if the user ZIP/postal code must be provided,- need_cardholder_name: True, if
	// the cardholder name must be provided
	//
	// Use SetNativeParams and GetNativeParams helpers.
	NativeParams DataJSON
	// Additional payment methods
	//
	// Use SetAdditionalMethods and GetAdditionalMethods helpers.
	AdditionalMethods []PaymentFormMethod
	// Saved server-side order information
	//
	// Use SetSavedInfo and GetSavedInfo helpers.
	SavedInfo PaymentRequestedInfo
	// Contains information about saved card credentials
	//
	// Use SetSavedCredentials and GetSavedCredentials helpers.
	SavedCredentials []PaymentSavedCredentialsCard
	// Users
	Users []UserClass
}

// PaymentsPaymentFormTypeID is TL type id of PaymentsPaymentForm.
const PaymentsPaymentFormTypeID = 0xa0058751

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

func ( *PaymentsPaymentForm) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.CanSaveCredentials == false) {
		return false
	}
	if !(.PasswordMissing == false) {
		return false
	}
	if !(.FormID == 0) {
		return false
	}
	if !(.BotID == 0) {
		return false
	}
	if !(.Title == "") {
		return false
	}
	if !(.Description == "") {
		return false
	}
	if !(.Photo == nil) {
		return false
	}
	if !(.Invoice.Zero()) {
		return false
	}
	if !(.ProviderID == 0) {
		return false
	}
	if !(.URL == "") {
		return false
	}
	if !(.NativeProvider == "") {
		return false
	}
	if !(.NativeParams.Zero()) {
		return false
	}
	if !(.AdditionalMethods == nil) {
		return false
	}
	if !(.SavedInfo.Zero()) {
		return false
	}
	if !(.SavedCredentials == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsPaymentForm from given interface.
func ( *PaymentsPaymentForm) ( interface {
	() ( bool)
	() ( bool)
	() ( int64)
	() ( int64)
	() ( string)
	() ( string)
	() ( WebDocumentClass,  bool)
	() ( Invoice)
	() ( int64)
	() ( string)
	() ( string,  bool)
	() ( DataJSON,  bool)
	() ( []PaymentFormMethod,  bool)
	() ( PaymentRequestedInfo,  bool)
	() ( []PaymentSavedCredentialsCard,  bool)
	() ( []UserClass)
}) {
	.CanSaveCredentials = .()
	.PasswordMissing = .()
	.FormID = .()
	.BotID = .()
	.Title = .()
	.Description = .()
	if ,  := .();  {
		.Photo = 
	}

	.Invoice = .()
	.ProviderID = .()
	.URL = .()
	if ,  := .();  {
		.NativeProvider = 
	}

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

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

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

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

	.Users = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsPaymentForm) () tdp.Type {
	 := tdp.Type{
		Name: "payments.paymentForm",
		ID:   PaymentsPaymentFormTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "CanSaveCredentials",
			SchemaName: "can_save_credentials",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "PasswordMissing",
			SchemaName: "password_missing",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "FormID",
			SchemaName: "form_id",
		},
		{
			Name:       "BotID",
			SchemaName: "bot_id",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "Description",
			SchemaName: "description",
		},
		{
			Name:       "Photo",
			SchemaName: "photo",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Invoice",
			SchemaName: "invoice",
		},
		{
			Name:       "ProviderID",
			SchemaName: "provider_id",
		},
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "NativeProvider",
			SchemaName: "native_provider",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "NativeParams",
			SchemaName: "native_params",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "AdditionalMethods",
			SchemaName: "additional_methods",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "SavedInfo",
			SchemaName: "saved_info",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "SavedCredentials",
			SchemaName: "saved_credentials",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PaymentsPaymentForm) () {
	if !(.CanSaveCredentials == false) {
		.Flags.Set(2)
	}
	if !(.PasswordMissing == false) {
		.Flags.Set(3)
	}
	if !(.Photo == nil) {
		.Flags.Set(5)
	}
	if !(.NativeProvider == "") {
		.Flags.Set(4)
	}
	if !(.NativeParams.Zero()) {
		.Flags.Set(4)
	}
	if !(.AdditionalMethods == nil) {
		.Flags.Set(6)
	}
	if !(.SavedInfo.Zero()) {
		.Flags.Set(0)
	}
	if !(.SavedCredentials == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *PaymentsPaymentForm) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.paymentForm#a0058751 as nil")
	}
	.PutID(PaymentsPaymentFormTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsPaymentForm) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.paymentForm#a0058751 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field flags: %w", )
	}
	.PutLong(.FormID)
	.PutLong(.BotID)
	.PutString(.Title)
	.PutString(.Description)
	if .Flags.Has(5) {
		if .Photo == nil {
			return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field photo is nil")
		}
		if  := .Photo.Encode();  != nil {
			return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field photo: %w", )
		}
	}
	if  := .Invoice.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field invoice: %w", )
	}
	.PutLong(.ProviderID)
	.PutString(.URL)
	if .Flags.Has(4) {
		.PutString(.NativeProvider)
	}
	if .Flags.Has(4) {
		if  := .NativeParams.Encode();  != nil {
			return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field native_params: %w", )
		}
	}
	if .Flags.Has(6) {
		.PutVectorHeader(len(.AdditionalMethods))
		for ,  := range .AdditionalMethods {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field additional_methods element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(0) {
		if  := .SavedInfo.Encode();  != nil {
			return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field saved_info: %w", )
		}
	}
	if .Flags.Has(1) {
		.PutVectorHeader(len(.SavedCredentials))
		for ,  := range .SavedCredentials {
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field saved_credentials element with index %d: %w", , )
			}
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.paymentForm#a0058751: field users element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsPaymentForm) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.paymentForm#a0058751 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field flags: %w", )
		}
	}
	.CanSaveCredentials = .Flags.Has(2)
	.PasswordMissing = .Flags.Has(3)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field form_id: %w", )
		}
		.FormID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field bot_id: %w", )
		}
		.BotID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field title: %w", )
		}
		.Title = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field description: %w", )
		}
		.Description = 
	}
	if .Flags.Has(5) {
		,  := DecodeWebDocument()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field photo: %w", )
		}
		.Photo = 
	}
	{
		if  := .Invoice.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field invoice: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field provider_id: %w", )
		}
		.ProviderID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field url: %w", )
		}
		.URL = 
	}
	if .Flags.Has(4) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field native_provider: %w", )
		}
		.NativeProvider = 
	}
	if .Flags.Has(4) {
		if  := .NativeParams.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field native_params: %w", )
		}
	}
	if .Flags.Has(6) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field additional_methods: %w", )
		}

		if  > 0 {
			.AdditionalMethods = make([]PaymentFormMethod, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  PaymentFormMethod
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field additional_methods: %w", )
			}
			.AdditionalMethods = append(.AdditionalMethods, )
		}
	}
	if .Flags.Has(0) {
		if  := .SavedInfo.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field saved_info: %w", )
		}
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field saved_credentials: %w", )
		}

		if  > 0 {
			.SavedCredentials = make([]PaymentSavedCredentialsCard, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  PaymentSavedCredentialsCard
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field saved_credentials: %w", )
			}
			.SavedCredentials = append(.SavedCredentials, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode payments.paymentForm#a0058751: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	return nil
}

// SetCanSaveCredentials sets value of CanSaveCredentials conditional field.
func ( *PaymentsPaymentForm) ( bool) {
	if  {
		.Flags.Set(2)
		.CanSaveCredentials = true
	} else {
		.Flags.Unset(2)
		.CanSaveCredentials = false
	}
}

// GetCanSaveCredentials returns value of CanSaveCredentials conditional field.
func ( *PaymentsPaymentForm) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetPasswordMissing sets value of PasswordMissing conditional field.
func ( *PaymentsPaymentForm) ( bool) {
	if  {
		.Flags.Set(3)
		.PasswordMissing = true
	} else {
		.Flags.Unset(3)
		.PasswordMissing = false
	}
}

// GetPasswordMissing returns value of PasswordMissing conditional field.
func ( *PaymentsPaymentForm) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// GetFormID returns value of FormID field.
func ( *PaymentsPaymentForm) () ( int64) {
	if  == nil {
		return
	}
	return .FormID
}

// GetBotID returns value of BotID field.
func ( *PaymentsPaymentForm) () ( int64) {
	if  == nil {
		return
	}
	return .BotID
}

// GetTitle returns value of Title field.
func ( *PaymentsPaymentForm) () ( string) {
	if  == nil {
		return
	}
	return .Title
}

// GetDescription returns value of Description field.
func ( *PaymentsPaymentForm) () ( string) {
	if  == nil {
		return
	}
	return .Description
}

// SetPhoto sets value of Photo conditional field.
func ( *PaymentsPaymentForm) ( WebDocumentClass) {
	.Flags.Set(5)
	.Photo = 
}

// GetPhoto returns value of Photo conditional field and
// boolean which is true if field was set.
func ( *PaymentsPaymentForm) () ( WebDocumentClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .Photo, true
}

// GetInvoice returns value of Invoice field.
func ( *PaymentsPaymentForm) () ( Invoice) {
	if  == nil {
		return
	}
	return .Invoice
}

// GetProviderID returns value of ProviderID field.
func ( *PaymentsPaymentForm) () ( int64) {
	if  == nil {
		return
	}
	return .ProviderID
}

// GetURL returns value of URL field.
func ( *PaymentsPaymentForm) () ( string) {
	if  == nil {
		return
	}
	return .URL
}

// SetNativeProvider sets value of NativeProvider conditional field.
func ( *PaymentsPaymentForm) ( string) {
	.Flags.Set(4)
	.NativeProvider = 
}

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

// SetNativeParams sets value of NativeParams conditional field.
func ( *PaymentsPaymentForm) ( DataJSON) {
	.Flags.Set(4)
	.NativeParams = 
}

// GetNativeParams returns value of NativeParams conditional field and
// boolean which is true if field was set.
func ( *PaymentsPaymentForm) () ( DataJSON,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .NativeParams, true
}

// SetAdditionalMethods sets value of AdditionalMethods conditional field.
func ( *PaymentsPaymentForm) ( []PaymentFormMethod) {
	.Flags.Set(6)
	.AdditionalMethods = 
}

// GetAdditionalMethods returns value of AdditionalMethods conditional field and
// boolean which is true if field was set.
func ( *PaymentsPaymentForm) () ( []PaymentFormMethod,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(6) {
		return , false
	}
	return .AdditionalMethods, true
}

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

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

// SetSavedCredentials sets value of SavedCredentials conditional field.
func ( *PaymentsPaymentForm) ( []PaymentSavedCredentialsCard) {
	.Flags.Set(1)
	.SavedCredentials = 
}

// GetSavedCredentials returns value of SavedCredentials conditional field and
// boolean which is true if field was set.
func ( *PaymentsPaymentForm) () ( []PaymentSavedCredentialsCard,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .SavedCredentials, true
}

// GetUsers returns value of Users field.
func ( *PaymentsPaymentForm) () ( []UserClass) {
	if  == nil {
		return
	}
	return .Users
}

// MapUsers returns field Users wrapped in UserClassArray helper.
func ( *PaymentsPaymentForm) () ( UserClassArray) {
	return UserClassArray(.Users)
}