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

// Invoice represents TL type `invoice#5db95a15`.
// Invoice
//
// See https://core.telegram.org/constructor/invoice for reference.
type Invoice struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Test invoice
	Test bool
	// Set this flag if you require the user's full name to complete the order
	NameRequested bool
	// Set this flag if you require the user's phone number to complete the order
	PhoneRequested bool
	// Set this flag if you require the user's email address to complete the order
	EmailRequested bool
	// Set this flag if you require the user's shipping address to complete the order
	ShippingAddressRequested bool
	// Set this flag if the final price depends on the shipping method
	Flexible bool
	// Set this flag if user's phone number should be sent to provider
	PhoneToProvider bool
	// Set this flag if user's email address should be sent to provider
	EmailToProvider bool
	// Whether this is a recurring payment
	Recurring bool
	// Three-letter ISO 4217 currency¹ code
	//
	// Links:
	//  1) https://core.telegram.org/bots/payments#supported-currencies
	Currency string
	// Price breakdown, a list of components (e.g. product price, tax, discount, delivery
	// cost, delivery tax, bonus, etc.)
	Prices []LabeledPrice
	// The maximum accepted amount for tips 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 SetMaxTipAmount and GetMaxTipAmount helpers.
	MaxTipAmount int64
	// A vector of suggested amounts of tips in the smallest units of the currency (integer,
	// not float/double). At most 4 suggested tip amounts can be specified. The suggested tip
	// amounts must be positive, passed in a strictly increased order and must not exceed
	// max_tip_amount.
	//
	// Use SetSuggestedTipAmounts and GetSuggestedTipAmounts helpers.
	SuggestedTipAmounts []int64
	// Terms of service URL
	//
	// Use SetTermsURL and GetTermsURL helpers.
	TermsURL string
}

// InvoiceTypeID is TL type id of Invoice.
const InvoiceTypeID = 0x5db95a15

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

func ( *Invoice) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Test == false) {
		return false
	}
	if !(.NameRequested == false) {
		return false
	}
	if !(.PhoneRequested == false) {
		return false
	}
	if !(.EmailRequested == false) {
		return false
	}
	if !(.ShippingAddressRequested == false) {
		return false
	}
	if !(.Flexible == false) {
		return false
	}
	if !(.PhoneToProvider == false) {
		return false
	}
	if !(.EmailToProvider == false) {
		return false
	}
	if !(.Recurring == false) {
		return false
	}
	if !(.Currency == "") {
		return false
	}
	if !(.Prices == nil) {
		return false
	}
	if !(.MaxTipAmount == 0) {
		return false
	}
	if !(.SuggestedTipAmounts == nil) {
		return false
	}
	if !(.TermsURL == "") {
		return false
	}

	return true
}

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

// FillFrom fills Invoice from given interface.
func ( *Invoice) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( string)
	() ( []LabeledPrice)
	() ( int64,  bool)
	() ( []int64,  bool)
	() ( string,  bool)
}) {
	.Test = .()
	.NameRequested = .()
	.PhoneRequested = .()
	.EmailRequested = .()
	.ShippingAddressRequested = .()
	.Flexible = .()
	.PhoneToProvider = .()
	.EmailToProvider = .()
	.Recurring = .()
	.Currency = .()
	.Prices = .()
	if ,  := .();  {
		.MaxTipAmount = 
	}

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *Invoice) () tdp.Type {
	 := tdp.Type{
		Name: "invoice",
		ID:   InvoiceTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Test",
			SchemaName: "test",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "NameRequested",
			SchemaName: "name_requested",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "PhoneRequested",
			SchemaName: "phone_requested",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "EmailRequested",
			SchemaName: "email_requested",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "ShippingAddressRequested",
			SchemaName: "shipping_address_requested",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "Flexible",
			SchemaName: "flexible",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "PhoneToProvider",
			SchemaName: "phone_to_provider",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "EmailToProvider",
			SchemaName: "email_to_provider",
			Null:       !.Flags.Has(7),
		},
		{
			Name:       "Recurring",
			SchemaName: "recurring",
			Null:       !.Flags.Has(9),
		},
		{
			Name:       "Currency",
			SchemaName: "currency",
		},
		{
			Name:       "Prices",
			SchemaName: "prices",
		},
		{
			Name:       "MaxTipAmount",
			SchemaName: "max_tip_amount",
			Null:       !.Flags.Has(8),
		},
		{
			Name:       "SuggestedTipAmounts",
			SchemaName: "suggested_tip_amounts",
			Null:       !.Flags.Has(8),
		},
		{
			Name:       "TermsURL",
			SchemaName: "terms_url",
			Null:       !.Flags.Has(10),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *Invoice) () {
	if !(.Test == false) {
		.Flags.Set(0)
	}
	if !(.NameRequested == false) {
		.Flags.Set(1)
	}
	if !(.PhoneRequested == false) {
		.Flags.Set(2)
	}
	if !(.EmailRequested == false) {
		.Flags.Set(3)
	}
	if !(.ShippingAddressRequested == false) {
		.Flags.Set(4)
	}
	if !(.Flexible == false) {
		.Flags.Set(5)
	}
	if !(.PhoneToProvider == false) {
		.Flags.Set(6)
	}
	if !(.EmailToProvider == false) {
		.Flags.Set(7)
	}
	if !(.Recurring == false) {
		.Flags.Set(9)
	}
	if !(.MaxTipAmount == 0) {
		.Flags.Set(8)
	}
	if !(.SuggestedTipAmounts == nil) {
		.Flags.Set(8)
	}
	if !(.TermsURL == "") {
		.Flags.Set(10)
	}
}

// Encode implements bin.Encoder.
func ( *Invoice) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode invoice#5db95a15 as nil")
	}
	.PutID(InvoiceTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *Invoice) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode invoice#5db95a15 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode invoice#5db95a15: field flags: %w", )
	}
	.PutString(.Currency)
	.PutVectorHeader(len(.Prices))
	for ,  := range .Prices {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode invoice#5db95a15: field prices element with index %d: %w", , )
		}
	}
	if .Flags.Has(8) {
		.PutLong(.MaxTipAmount)
	}
	if .Flags.Has(8) {
		.PutVectorHeader(len(.SuggestedTipAmounts))
		for ,  := range .SuggestedTipAmounts {
			.PutLong()
		}
	}
	if .Flags.Has(10) {
		.PutString(.TermsURL)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *Invoice) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode invoice#5db95a15 to nil")
	}
	if  := .ConsumeID(InvoiceTypeID);  != nil {
		return fmt.Errorf("unable to decode invoice#5db95a15: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *Invoice) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode invoice#5db95a15 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode invoice#5db95a15: field flags: %w", )
		}
	}
	.Test = .Flags.Has(0)
	.NameRequested = .Flags.Has(1)
	.PhoneRequested = .Flags.Has(2)
	.EmailRequested = .Flags.Has(3)
	.ShippingAddressRequested = .Flags.Has(4)
	.Flexible = .Flags.Has(5)
	.PhoneToProvider = .Flags.Has(6)
	.EmailToProvider = .Flags.Has(7)
	.Recurring = .Flags.Has(9)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode invoice#5db95a15: field currency: %w", )
		}
		.Currency = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode invoice#5db95a15: field prices: %w", )
		}

		if  > 0 {
			.Prices = make([]LabeledPrice, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  LabeledPrice
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode invoice#5db95a15: field prices: %w", )
			}
			.Prices = append(.Prices, )
		}
	}
	if .Flags.Has(8) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode invoice#5db95a15: field max_tip_amount: %w", )
		}
		.MaxTipAmount = 
	}
	if .Flags.Has(8) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode invoice#5db95a15: field suggested_tip_amounts: %w", )
		}

		if  > 0 {
			.SuggestedTipAmounts = make([]int64, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .Long()
			if  != nil {
				return fmt.Errorf("unable to decode invoice#5db95a15: field suggested_tip_amounts: %w", )
			}
			.SuggestedTipAmounts = append(.SuggestedTipAmounts, )
		}
	}
	if .Flags.Has(10) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode invoice#5db95a15: field terms_url: %w", )
		}
		.TermsURL = 
	}
	return nil
}

// SetTest sets value of Test conditional field.
func ( *Invoice) ( bool) {
	if  {
		.Flags.Set(0)
		.Test = true
	} else {
		.Flags.Unset(0)
		.Test = false
	}
}

// GetTest returns value of Test conditional field.
func ( *Invoice) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetNameRequested sets value of NameRequested conditional field.
func ( *Invoice) ( bool) {
	if  {
		.Flags.Set(1)
		.NameRequested = true
	} else {
		.Flags.Unset(1)
		.NameRequested = false
	}
}

// GetNameRequested returns value of NameRequested conditional field.
func ( *Invoice) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetPhoneRequested sets value of PhoneRequested conditional field.
func ( *Invoice) ( bool) {
	if  {
		.Flags.Set(2)
		.PhoneRequested = true
	} else {
		.Flags.Unset(2)
		.PhoneRequested = false
	}
}

// GetPhoneRequested returns value of PhoneRequested conditional field.
func ( *Invoice) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetEmailRequested sets value of EmailRequested conditional field.
func ( *Invoice) ( bool) {
	if  {
		.Flags.Set(3)
		.EmailRequested = true
	} else {
		.Flags.Unset(3)
		.EmailRequested = false
	}
}

// GetEmailRequested returns value of EmailRequested conditional field.
func ( *Invoice) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetShippingAddressRequested sets value of ShippingAddressRequested conditional field.
func ( *Invoice) ( bool) {
	if  {
		.Flags.Set(4)
		.ShippingAddressRequested = true
	} else {
		.Flags.Unset(4)
		.ShippingAddressRequested = false
	}
}

// GetShippingAddressRequested returns value of ShippingAddressRequested conditional field.
func ( *Invoice) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// SetFlexible sets value of Flexible conditional field.
func ( *Invoice) ( bool) {
	if  {
		.Flags.Set(5)
		.Flexible = true
	} else {
		.Flags.Unset(5)
		.Flexible = false
	}
}

// GetFlexible returns value of Flexible conditional field.
func ( *Invoice) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

// SetPhoneToProvider sets value of PhoneToProvider conditional field.
func ( *Invoice) ( bool) {
	if  {
		.Flags.Set(6)
		.PhoneToProvider = true
	} else {
		.Flags.Unset(6)
		.PhoneToProvider = false
	}
}

// GetPhoneToProvider returns value of PhoneToProvider conditional field.
func ( *Invoice) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(6)
}

// SetEmailToProvider sets value of EmailToProvider conditional field.
func ( *Invoice) ( bool) {
	if  {
		.Flags.Set(7)
		.EmailToProvider = true
	} else {
		.Flags.Unset(7)
		.EmailToProvider = false
	}
}

// GetEmailToProvider returns value of EmailToProvider conditional field.
func ( *Invoice) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(7)
}

// SetRecurring sets value of Recurring conditional field.
func ( *Invoice) ( bool) {
	if  {
		.Flags.Set(9)
		.Recurring = true
	} else {
		.Flags.Unset(9)
		.Recurring = false
	}
}

// GetRecurring returns value of Recurring conditional field.
func ( *Invoice) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(9)
}

// GetCurrency returns value of Currency field.
func ( *Invoice) () ( string) {
	if  == nil {
		return
	}
	return .Currency
}

// GetPrices returns value of Prices field.
func ( *Invoice) () ( []LabeledPrice) {
	if  == nil {
		return
	}
	return .Prices
}

// SetMaxTipAmount sets value of MaxTipAmount conditional field.
func ( *Invoice) ( int64) {
	.Flags.Set(8)
	.MaxTipAmount = 
}

// GetMaxTipAmount returns value of MaxTipAmount conditional field and
// boolean which is true if field was set.
func ( *Invoice) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(8) {
		return , false
	}
	return .MaxTipAmount, true
}

// SetSuggestedTipAmounts sets value of SuggestedTipAmounts conditional field.
func ( *Invoice) ( []int64) {
	.Flags.Set(8)
	.SuggestedTipAmounts = 
}

// GetSuggestedTipAmounts returns value of SuggestedTipAmounts conditional field and
// boolean which is true if field was set.
func ( *Invoice) () ( []int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(8) {
		return , false
	}
	return .SuggestedTipAmounts, true
}

// SetTermsURL sets value of TermsURL conditional field.
func ( *Invoice) ( string) {
	.Flags.Set(10)
	.TermsURL = 
}

// GetTermsURL returns value of TermsURL conditional field and
// boolean which is true if field was set.
func ( *Invoice) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(10) {
		return , false
	}
	return .TermsURL, true
}