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 PremiumSubscriptionOption struct {
Flags bin .Fields
Current bool
CanPurchaseUpgrade bool
Transaction string
Months int
Currency string
Amount int64
BotURL string
StoreProduct string
}
const PremiumSubscriptionOptionTypeID = 0x5f2d1df2
var (
_ bin .Encoder = &PremiumSubscriptionOption {}
_ bin .Decoder = &PremiumSubscriptionOption {}
_ bin .BareEncoder = &PremiumSubscriptionOption {}
_ bin .BareDecoder = &PremiumSubscriptionOption {}
)
func (p *PremiumSubscriptionOption ) Zero () bool {
if p == nil {
return true
}
if !(p .Flags .Zero ()) {
return false
}
if !(p .Current == false ) {
return false
}
if !(p .CanPurchaseUpgrade == false ) {
return false
}
if !(p .Transaction == "" ) {
return false
}
if !(p .Months == 0 ) {
return false
}
if !(p .Currency == "" ) {
return false
}
if !(p .Amount == 0 ) {
return false
}
if !(p .BotURL == "" ) {
return false
}
if !(p .StoreProduct == "" ) {
return false
}
return true
}
func (p *PremiumSubscriptionOption ) String () string {
if p == nil {
return "PremiumSubscriptionOption(nil)"
}
type Alias PremiumSubscriptionOption
return fmt .Sprintf ("PremiumSubscriptionOption%+v" , Alias (*p ))
}
func (p *PremiumSubscriptionOption ) FillFrom (from interface {
GetCurrent () (value bool )
GetCanPurchaseUpgrade () (value bool )
GetTransaction () (value string , ok bool )
GetMonths () (value int )
GetCurrency () (value string )
GetAmount () (value int64 )
GetBotURL () (value string )
GetStoreProduct () (value string , ok bool )
}) {
p .Current = from .GetCurrent ()
p .CanPurchaseUpgrade = from .GetCanPurchaseUpgrade ()
if val , ok := from .GetTransaction (); ok {
p .Transaction = val
}
p .Months = from .GetMonths ()
p .Currency = from .GetCurrency ()
p .Amount = from .GetAmount ()
p .BotURL = from .GetBotURL ()
if val , ok := from .GetStoreProduct (); ok {
p .StoreProduct = val
}
}
func (*PremiumSubscriptionOption ) TypeID () uint32 {
return PremiumSubscriptionOptionTypeID
}
func (*PremiumSubscriptionOption ) TypeName () string {
return "premiumSubscriptionOption"
}
func (p *PremiumSubscriptionOption ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "premiumSubscriptionOption" ,
ID : PremiumSubscriptionOptionTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Current" ,
SchemaName : "current" ,
Null : !p .Flags .Has (1 ),
},
{
Name : "CanPurchaseUpgrade" ,
SchemaName : "can_purchase_upgrade" ,
Null : !p .Flags .Has (2 ),
},
{
Name : "Transaction" ,
SchemaName : "transaction" ,
Null : !p .Flags .Has (3 ),
},
{
Name : "Months" ,
SchemaName : "months" ,
},
{
Name : "Currency" ,
SchemaName : "currency" ,
},
{
Name : "Amount" ,
SchemaName : "amount" ,
},
{
Name : "BotURL" ,
SchemaName : "bot_url" ,
},
{
Name : "StoreProduct" ,
SchemaName : "store_product" ,
Null : !p .Flags .Has (0 ),
},
}
return typ
}
func (p *PremiumSubscriptionOption ) SetFlags () {
if !(p .Current == false ) {
p .Flags .Set (1 )
}
if !(p .CanPurchaseUpgrade == false ) {
p .Flags .Set (2 )
}
if !(p .Transaction == "" ) {
p .Flags .Set (3 )
}
if !(p .StoreProduct == "" ) {
p .Flags .Set (0 )
}
}
func (p *PremiumSubscriptionOption ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode premiumSubscriptionOption#5f2d1df2 as nil" )
}
b .PutID (PremiumSubscriptionOptionTypeID )
return p .EncodeBare (b )
}
func (p *PremiumSubscriptionOption ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode premiumSubscriptionOption#5f2d1df2 as nil" )
}
p .SetFlags ()
if err := p .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode premiumSubscriptionOption#5f2d1df2: field flags: %w" , err )
}
if p .Flags .Has (3 ) {
b .PutString (p .Transaction )
}
b .PutInt (p .Months )
b .PutString (p .Currency )
b .PutLong (p .Amount )
b .PutString (p .BotURL )
if p .Flags .Has (0 ) {
b .PutString (p .StoreProduct )
}
return nil
}
func (p *PremiumSubscriptionOption ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode premiumSubscriptionOption#5f2d1df2 to nil" )
}
if err := b .ConsumeID (PremiumSubscriptionOptionTypeID ); err != nil {
return fmt .Errorf ("unable to decode premiumSubscriptionOption#5f2d1df2: %w" , err )
}
return p .DecodeBare (b )
}
func (p *PremiumSubscriptionOption ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode premiumSubscriptionOption#5f2d1df2 to nil" )
}
{
if err := p .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode premiumSubscriptionOption#5f2d1df2: field flags: %w" , err )
}
}
p .Current = p .Flags .Has (1 )
p .CanPurchaseUpgrade = p .Flags .Has (2 )
if p .Flags .Has (3 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode premiumSubscriptionOption#5f2d1df2: field transaction: %w" , err )
}
p .Transaction = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode premiumSubscriptionOption#5f2d1df2: field months: %w" , err )
}
p .Months = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode premiumSubscriptionOption#5f2d1df2: field currency: %w" , err )
}
p .Currency = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode premiumSubscriptionOption#5f2d1df2: field amount: %w" , err )
}
p .Amount = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode premiumSubscriptionOption#5f2d1df2: field bot_url: %w" , err )
}
p .BotURL = value
}
if p .Flags .Has (0 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode premiumSubscriptionOption#5f2d1df2: field store_product: %w" , err )
}
p .StoreProduct = value
}
return nil
}
func (p *PremiumSubscriptionOption ) SetCurrent (value bool ) {
if value {
p .Flags .Set (1 )
p .Current = true
} else {
p .Flags .Unset (1 )
p .Current = false
}
}
func (p *PremiumSubscriptionOption ) GetCurrent () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (1 )
}
func (p *PremiumSubscriptionOption ) SetCanPurchaseUpgrade (value bool ) {
if value {
p .Flags .Set (2 )
p .CanPurchaseUpgrade = true
} else {
p .Flags .Unset (2 )
p .CanPurchaseUpgrade = false
}
}
func (p *PremiumSubscriptionOption ) GetCanPurchaseUpgrade () (value bool ) {
if p == nil {
return
}
return p .Flags .Has (2 )
}
func (p *PremiumSubscriptionOption ) SetTransaction (value string ) {
p .Flags .Set (3 )
p .Transaction = value
}
func (p *PremiumSubscriptionOption ) GetTransaction () (value string , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (3 ) {
return value , false
}
return p .Transaction , true
}
func (p *PremiumSubscriptionOption ) GetMonths () (value int ) {
if p == nil {
return
}
return p .Months
}
func (p *PremiumSubscriptionOption ) GetCurrency () (value string ) {
if p == nil {
return
}
return p .Currency
}
func (p *PremiumSubscriptionOption ) GetAmount () (value int64 ) {
if p == nil {
return
}
return p .Amount
}
func (p *PremiumSubscriptionOption ) GetBotURL () (value string ) {
if p == nil {
return
}
return p .BotURL
}
func (p *PremiumSubscriptionOption ) SetStoreProduct (value string ) {
p .Flags .Set (0 )
p .StoreProduct = value
}
func (p *PremiumSubscriptionOption ) GetStoreProduct () (value string , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (0 ) {
return value , false
}
return p .StoreProduct , 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 .