package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type Invoice struct {
Flags bin .Fields
Test bool
NameRequested bool
PhoneRequested bool
EmailRequested bool
ShippingAddressRequested bool
Flexible bool
PhoneToProvider bool
EmailToProvider bool
Recurring bool
Currency string
Prices []LabeledPrice
MaxTipAmount int64
SuggestedTipAmounts []int64
TermsURL string
}
const InvoiceTypeID = 0x5db95a15
var (
_ bin .Encoder = &Invoice {}
_ bin .Decoder = &Invoice {}
_ bin .BareEncoder = &Invoice {}
_ bin .BareDecoder = &Invoice {}
)
func (i *Invoice ) Zero () bool {
if i == nil {
return true
}
if !(i .Flags .Zero ()) {
return false
}
if !(i .Test == false ) {
return false
}
if !(i .NameRequested == false ) {
return false
}
if !(i .PhoneRequested == false ) {
return false
}
if !(i .EmailRequested == false ) {
return false
}
if !(i .ShippingAddressRequested == false ) {
return false
}
if !(i .Flexible == false ) {
return false
}
if !(i .PhoneToProvider == false ) {
return false
}
if !(i .EmailToProvider == false ) {
return false
}
if !(i .Recurring == false ) {
return false
}
if !(i .Currency == "" ) {
return false
}
if !(i .Prices == nil ) {
return false
}
if !(i .MaxTipAmount == 0 ) {
return false
}
if !(i .SuggestedTipAmounts == nil ) {
return false
}
if !(i .TermsURL == "" ) {
return false
}
return true
}
func (i *Invoice ) String () string {
if i == nil {
return "Invoice(nil)"
}
type Alias Invoice
return fmt .Sprintf ("Invoice%+v" , Alias (*i ))
}
func (i *Invoice ) FillFrom (from interface {
GetTest () (value bool )
GetNameRequested () (value bool )
GetPhoneRequested () (value bool )
GetEmailRequested () (value bool )
GetShippingAddressRequested () (value bool )
GetFlexible () (value bool )
GetPhoneToProvider () (value bool )
GetEmailToProvider () (value bool )
GetRecurring () (value bool )
GetCurrency () (value string )
GetPrices () (value []LabeledPrice )
GetMaxTipAmount () (value int64 , ok bool )
GetSuggestedTipAmounts () (value []int64 , ok bool )
GetTermsURL () (value string , ok bool )
}) {
i .Test = from .GetTest ()
i .NameRequested = from .GetNameRequested ()
i .PhoneRequested = from .GetPhoneRequested ()
i .EmailRequested = from .GetEmailRequested ()
i .ShippingAddressRequested = from .GetShippingAddressRequested ()
i .Flexible = from .GetFlexible ()
i .PhoneToProvider = from .GetPhoneToProvider ()
i .EmailToProvider = from .GetEmailToProvider ()
i .Recurring = from .GetRecurring ()
i .Currency = from .GetCurrency ()
i .Prices = from .GetPrices ()
if val , ok := from .GetMaxTipAmount (); ok {
i .MaxTipAmount = val
}
if val , ok := from .GetSuggestedTipAmounts (); ok {
i .SuggestedTipAmounts = val
}
if val , ok := from .GetTermsURL (); ok {
i .TermsURL = val
}
}
func (*Invoice ) TypeID () uint32 {
return InvoiceTypeID
}
func (*Invoice ) TypeName () string {
return "invoice"
}
func (i *Invoice ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "invoice" ,
ID : InvoiceTypeID ,
}
if i == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Test" ,
SchemaName : "test" ,
Null : !i .Flags .Has (0 ),
},
{
Name : "NameRequested" ,
SchemaName : "name_requested" ,
Null : !i .Flags .Has (1 ),
},
{
Name : "PhoneRequested" ,
SchemaName : "phone_requested" ,
Null : !i .Flags .Has (2 ),
},
{
Name : "EmailRequested" ,
SchemaName : "email_requested" ,
Null : !i .Flags .Has (3 ),
},
{
Name : "ShippingAddressRequested" ,
SchemaName : "shipping_address_requested" ,
Null : !i .Flags .Has (4 ),
},
{
Name : "Flexible" ,
SchemaName : "flexible" ,
Null : !i .Flags .Has (5 ),
},
{
Name : "PhoneToProvider" ,
SchemaName : "phone_to_provider" ,
Null : !i .Flags .Has (6 ),
},
{
Name : "EmailToProvider" ,
SchemaName : "email_to_provider" ,
Null : !i .Flags .Has (7 ),
},
{
Name : "Recurring" ,
SchemaName : "recurring" ,
Null : !i .Flags .Has (9 ),
},
{
Name : "Currency" ,
SchemaName : "currency" ,
},
{
Name : "Prices" ,
SchemaName : "prices" ,
},
{
Name : "MaxTipAmount" ,
SchemaName : "max_tip_amount" ,
Null : !i .Flags .Has (8 ),
},
{
Name : "SuggestedTipAmounts" ,
SchemaName : "suggested_tip_amounts" ,
Null : !i .Flags .Has (8 ),
},
{
Name : "TermsURL" ,
SchemaName : "terms_url" ,
Null : !i .Flags .Has (10 ),
},
}
return typ
}
func (i *Invoice ) SetFlags () {
if !(i .Test == false ) {
i .Flags .Set (0 )
}
if !(i .NameRequested == false ) {
i .Flags .Set (1 )
}
if !(i .PhoneRequested == false ) {
i .Flags .Set (2 )
}
if !(i .EmailRequested == false ) {
i .Flags .Set (3 )
}
if !(i .ShippingAddressRequested == false ) {
i .Flags .Set (4 )
}
if !(i .Flexible == false ) {
i .Flags .Set (5 )
}
if !(i .PhoneToProvider == false ) {
i .Flags .Set (6 )
}
if !(i .EmailToProvider == false ) {
i .Flags .Set (7 )
}
if !(i .Recurring == false ) {
i .Flags .Set (9 )
}
if !(i .MaxTipAmount == 0 ) {
i .Flags .Set (8 )
}
if !(i .SuggestedTipAmounts == nil ) {
i .Flags .Set (8 )
}
if !(i .TermsURL == "" ) {
i .Flags .Set (10 )
}
}
func (i *Invoice ) Encode (b *bin .Buffer ) error {
if i == nil {
return fmt .Errorf ("can't encode invoice#5db95a15 as nil" )
}
b .PutID (InvoiceTypeID )
return i .EncodeBare (b )
}
func (i *Invoice ) EncodeBare (b *bin .Buffer ) error {
if i == nil {
return fmt .Errorf ("can't encode invoice#5db95a15 as nil" )
}
i .SetFlags ()
if err := i .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode invoice#5db95a15: field flags: %w" , err )
}
b .PutString (i .Currency )
b .PutVectorHeader (len (i .Prices ))
for idx , v := range i .Prices {
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode invoice#5db95a15: field prices element with index %d: %w" , idx , err )
}
}
if i .Flags .Has (8 ) {
b .PutLong (i .MaxTipAmount )
}
if i .Flags .Has (8 ) {
b .PutVectorHeader (len (i .SuggestedTipAmounts ))
for _ , v := range i .SuggestedTipAmounts {
b .PutLong (v )
}
}
if i .Flags .Has (10 ) {
b .PutString (i .TermsURL )
}
return nil
}
func (i *Invoice ) Decode (b *bin .Buffer ) error {
if i == nil {
return fmt .Errorf ("can't decode invoice#5db95a15 to nil" )
}
if err := b .ConsumeID (InvoiceTypeID ); err != nil {
return fmt .Errorf ("unable to decode invoice#5db95a15: %w" , err )
}
return i .DecodeBare (b )
}
func (i *Invoice ) DecodeBare (b *bin .Buffer ) error {
if i == nil {
return fmt .Errorf ("can't decode invoice#5db95a15 to nil" )
}
{
if err := i .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode invoice#5db95a15: field flags: %w" , err )
}
}
i .Test = i .Flags .Has (0 )
i .NameRequested = i .Flags .Has (1 )
i .PhoneRequested = i .Flags .Has (2 )
i .EmailRequested = i .Flags .Has (3 )
i .ShippingAddressRequested = i .Flags .Has (4 )
i .Flexible = i .Flags .Has (5 )
i .PhoneToProvider = i .Flags .Has (6 )
i .EmailToProvider = i .Flags .Has (7 )
i .Recurring = i .Flags .Has (9 )
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode invoice#5db95a15: field currency: %w" , err )
}
i .Currency = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode invoice#5db95a15: field prices: %w" , err )
}
if headerLen > 0 {
i .Prices = make ([]LabeledPrice , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
var value LabeledPrice
if err := value .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode invoice#5db95a15: field prices: %w" , err )
}
i .Prices = append (i .Prices , value )
}
}
if i .Flags .Has (8 ) {
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode invoice#5db95a15: field max_tip_amount: %w" , err )
}
i .MaxTipAmount = value
}
if i .Flags .Has (8 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode invoice#5db95a15: field suggested_tip_amounts: %w" , err )
}
if headerLen > 0 {
i .SuggestedTipAmounts = make ([]int64 , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode invoice#5db95a15: field suggested_tip_amounts: %w" , err )
}
i .SuggestedTipAmounts = append (i .SuggestedTipAmounts , value )
}
}
if i .Flags .Has (10 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode invoice#5db95a15: field terms_url: %w" , err )
}
i .TermsURL = value
}
return nil
}
func (i *Invoice ) SetTest (value bool ) {
if value {
i .Flags .Set (0 )
i .Test = true
} else {
i .Flags .Unset (0 )
i .Test = false
}
}
func (i *Invoice ) GetTest () (value bool ) {
if i == nil {
return
}
return i .Flags .Has (0 )
}
func (i *Invoice ) SetNameRequested (value bool ) {
if value {
i .Flags .Set (1 )
i .NameRequested = true
} else {
i .Flags .Unset (1 )
i .NameRequested = false
}
}
func (i *Invoice ) GetNameRequested () (value bool ) {
if i == nil {
return
}
return i .Flags .Has (1 )
}
func (i *Invoice ) SetPhoneRequested (value bool ) {
if value {
i .Flags .Set (2 )
i .PhoneRequested = true
} else {
i .Flags .Unset (2 )
i .PhoneRequested = false
}
}
func (i *Invoice ) GetPhoneRequested () (value bool ) {
if i == nil {
return
}
return i .Flags .Has (2 )
}
func (i *Invoice ) SetEmailRequested (value bool ) {
if value {
i .Flags .Set (3 )
i .EmailRequested = true
} else {
i .Flags .Unset (3 )
i .EmailRequested = false
}
}
func (i *Invoice ) GetEmailRequested () (value bool ) {
if i == nil {
return
}
return i .Flags .Has (3 )
}
func (i *Invoice ) SetShippingAddressRequested (value bool ) {
if value {
i .Flags .Set (4 )
i .ShippingAddressRequested = true
} else {
i .Flags .Unset (4 )
i .ShippingAddressRequested = false
}
}
func (i *Invoice ) GetShippingAddressRequested () (value bool ) {
if i == nil {
return
}
return i .Flags .Has (4 )
}
func (i *Invoice ) SetFlexible (value bool ) {
if value {
i .Flags .Set (5 )
i .Flexible = true
} else {
i .Flags .Unset (5 )
i .Flexible = false
}
}
func (i *Invoice ) GetFlexible () (value bool ) {
if i == nil {
return
}
return i .Flags .Has (5 )
}
func (i *Invoice ) SetPhoneToProvider (value bool ) {
if value {
i .Flags .Set (6 )
i .PhoneToProvider = true
} else {
i .Flags .Unset (6 )
i .PhoneToProvider = false
}
}
func (i *Invoice ) GetPhoneToProvider () (value bool ) {
if i == nil {
return
}
return i .Flags .Has (6 )
}
func (i *Invoice ) SetEmailToProvider (value bool ) {
if value {
i .Flags .Set (7 )
i .EmailToProvider = true
} else {
i .Flags .Unset (7 )
i .EmailToProvider = false
}
}
func (i *Invoice ) GetEmailToProvider () (value bool ) {
if i == nil {
return
}
return i .Flags .Has (7 )
}
func (i *Invoice ) SetRecurring (value bool ) {
if value {
i .Flags .Set (9 )
i .Recurring = true
} else {
i .Flags .Unset (9 )
i .Recurring = false
}
}
func (i *Invoice ) GetRecurring () (value bool ) {
if i == nil {
return
}
return i .Flags .Has (9 )
}
func (i *Invoice ) GetCurrency () (value string ) {
if i == nil {
return
}
return i .Currency
}
func (i *Invoice ) GetPrices () (value []LabeledPrice ) {
if i == nil {
return
}
return i .Prices
}
func (i *Invoice ) SetMaxTipAmount (value int64 ) {
i .Flags .Set (8 )
i .MaxTipAmount = value
}
func (i *Invoice ) GetMaxTipAmount () (value int64 , ok bool ) {
if i == nil {
return
}
if !i .Flags .Has (8 ) {
return value , false
}
return i .MaxTipAmount , true
}
func (i *Invoice ) SetSuggestedTipAmounts (value []int64 ) {
i .Flags .Set (8 )
i .SuggestedTipAmounts = value
}
func (i *Invoice ) GetSuggestedTipAmounts () (value []int64 , ok bool ) {
if i == nil {
return
}
if !i .Flags .Has (8 ) {
return value , false
}
return i .SuggestedTipAmounts , true
}
func (i *Invoice ) SetTermsURL (value string ) {
i .Flags .Set (10 )
i .TermsURL = value
}
func (i *Invoice ) GetTermsURL () (value string , ok bool ) {
if i == nil {
return
}
if !i .Flags .Has (10 ) {
return value , false
}
return i .TermsURL , true
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .