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

// PaymentsSendPaymentFormRequest represents TL type `payments.sendPaymentForm#2d03522f`.
// Send compiled payment form
//
// See https://core.telegram.org/method/payments.sendPaymentForm for reference.
type PaymentsSendPaymentFormRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Form ID
	FormID int64
	// Invoice
	Invoice InputInvoiceClass
	// ID of saved and validated order info¹
	//
	// Links:
	//  1) https://core.telegram.org/constructor/payments.validatedRequestedInfo
	//
	// Use SetRequestedInfoID and GetRequestedInfoID helpers.
	RequestedInfoID string
	// Chosen shipping option ID
	//
	// Use SetShippingOptionID and GetShippingOptionID helpers.
	ShippingOptionID string
	// Payment credentials
	Credentials InputPaymentCredentialsClass
	// Tip, in the smallest units of the currency (integer, not float/double). For example,
	// for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json¹,
	// it shows the number of digits past the decimal point for each currency (2 for the
	// majority of currencies).
	//
	// Links:
	//  1) https://core.telegram.org/bots/payments/currencies.json
	//
	// Use SetTipAmount and GetTipAmount helpers.
	TipAmount int64
}

// PaymentsSendPaymentFormRequestTypeID is TL type id of PaymentsSendPaymentFormRequest.
const PaymentsSendPaymentFormRequestTypeID = 0x2d03522f

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

func ( *PaymentsSendPaymentFormRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.FormID == 0) {
		return false
	}
	if !(.Invoice == nil) {
		return false
	}
	if !(.RequestedInfoID == "") {
		return false
	}
	if !(.ShippingOptionID == "") {
		return false
	}
	if !(.Credentials == nil) {
		return false
	}
	if !(.TipAmount == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsSendPaymentFormRequest from given interface.
func ( *PaymentsSendPaymentFormRequest) ( interface {
	() ( int64)
	() ( InputInvoiceClass)
	() ( string,  bool)
	() ( string,  bool)
	() ( InputPaymentCredentialsClass)
	() ( int64,  bool)
}) {
	.FormID = .()
	.Invoice = .()
	if ,  := .();  {
		.RequestedInfoID = 
	}

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

	.Credentials = .()
	if ,  := .();  {
		.TipAmount = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsSendPaymentFormRequest) () tdp.Type {
	 := tdp.Type{
		Name: "payments.sendPaymentForm",
		ID:   PaymentsSendPaymentFormRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "FormID",
			SchemaName: "form_id",
		},
		{
			Name:       "Invoice",
			SchemaName: "invoice",
		},
		{
			Name:       "RequestedInfoID",
			SchemaName: "requested_info_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "ShippingOptionID",
			SchemaName: "shipping_option_id",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Credentials",
			SchemaName: "credentials",
		},
		{
			Name:       "TipAmount",
			SchemaName: "tip_amount",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PaymentsSendPaymentFormRequest) () {
	if !(.RequestedInfoID == "") {
		.Flags.Set(0)
	}
	if !(.ShippingOptionID == "") {
		.Flags.Set(1)
	}
	if !(.TipAmount == 0) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *PaymentsSendPaymentFormRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.sendPaymentForm#2d03522f as nil")
	}
	.PutID(PaymentsSendPaymentFormRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsSendPaymentFormRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.sendPaymentForm#2d03522f as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field flags: %w", )
	}
	.PutLong(.FormID)
	if .Invoice == nil {
		return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field invoice is nil")
	}
	if  := .Invoice.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field invoice: %w", )
	}
	if .Flags.Has(0) {
		.PutString(.RequestedInfoID)
	}
	if .Flags.Has(1) {
		.PutString(.ShippingOptionID)
	}
	if .Credentials == nil {
		return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field credentials is nil")
	}
	if  := .Credentials.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.sendPaymentForm#2d03522f: field credentials: %w", )
	}
	if .Flags.Has(2) {
		.PutLong(.TipAmount)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsSendPaymentFormRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.sendPaymentForm#2d03522f to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field flags: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field form_id: %w", )
		}
		.FormID = 
	}
	{
		,  := DecodeInputInvoice()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field invoice: %w", )
		}
		.Invoice = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field requested_info_id: %w", )
		}
		.RequestedInfoID = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field shipping_option_id: %w", )
		}
		.ShippingOptionID = 
	}
	{
		,  := DecodeInputPaymentCredentials()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field credentials: %w", )
		}
		.Credentials = 
	}
	if .Flags.Has(2) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode payments.sendPaymentForm#2d03522f: field tip_amount: %w", )
		}
		.TipAmount = 
	}
	return nil
}

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

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

// SetRequestedInfoID sets value of RequestedInfoID conditional field.
func ( *PaymentsSendPaymentFormRequest) ( string) {
	.Flags.Set(0)
	.RequestedInfoID = 
}

// GetRequestedInfoID returns value of RequestedInfoID conditional field and
// boolean which is true if field was set.
func ( *PaymentsSendPaymentFormRequest) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .RequestedInfoID, true
}

// SetShippingOptionID sets value of ShippingOptionID conditional field.
func ( *PaymentsSendPaymentFormRequest) ( string) {
	.Flags.Set(1)
	.ShippingOptionID = 
}

// GetShippingOptionID returns value of ShippingOptionID conditional field and
// boolean which is true if field was set.
func ( *PaymentsSendPaymentFormRequest) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .ShippingOptionID, true
}

// GetCredentials returns value of Credentials field.
func ( *PaymentsSendPaymentFormRequest) () ( InputPaymentCredentialsClass) {
	if  == nil {
		return
	}
	return .Credentials
}

// SetTipAmount sets value of TipAmount conditional field.
func ( *PaymentsSendPaymentFormRequest) ( int64) {
	.Flags.Set(2)
	.TipAmount = 
}

// GetTipAmount returns value of TipAmount conditional field and
// boolean which is true if field was set.
func ( *PaymentsSendPaymentFormRequest) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .TipAmount, true
}

// PaymentsSendPaymentForm invokes method payments.sendPaymentForm#2d03522f returning error if any.
// Send compiled payment form
//
// Possible errors:
//
//	400 MESSAGE_ID_INVALID: The provided message id is invalid.
//
// See https://core.telegram.org/method/payments.sendPaymentForm for reference.
func ( *Client) ( context.Context,  *PaymentsSendPaymentFormRequest) (PaymentsPaymentResultClass, error) {
	var  PaymentsPaymentResultBox

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return .PaymentResult, nil
}