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 PremiumGiftOption struct {
Flags bin .Fields
Months int
Currency string
Amount int64
BotURL string
StoreProduct string
}
const PremiumGiftOptionTypeID = 0x74c34319
var (
_ bin .Encoder = &PremiumGiftOption {}
_ bin .Decoder = &PremiumGiftOption {}
_ bin .BareEncoder = &PremiumGiftOption {}
_ bin .BareDecoder = &PremiumGiftOption {}
)
func (p *PremiumGiftOption ) Zero () bool {
if p == nil {
return true
}
if !(p .Flags .Zero ()) {
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 *PremiumGiftOption ) String () string {
if p == nil {
return "PremiumGiftOption(nil)"
}
type Alias PremiumGiftOption
return fmt .Sprintf ("PremiumGiftOption%+v" , Alias (*p ))
}
func (p *PremiumGiftOption ) FillFrom (from interface {
GetMonths () (value int )
GetCurrency () (value string )
GetAmount () (value int64 )
GetBotURL () (value string )
GetStoreProduct () (value string , ok bool )
}) {
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 (*PremiumGiftOption ) TypeID () uint32 {
return PremiumGiftOptionTypeID
}
func (*PremiumGiftOption ) TypeName () string {
return "premiumGiftOption"
}
func (p *PremiumGiftOption ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "premiumGiftOption" ,
ID : PremiumGiftOptionTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
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 *PremiumGiftOption ) SetFlags () {
if !(p .StoreProduct == "" ) {
p .Flags .Set (0 )
}
}
func (p *PremiumGiftOption ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode premiumGiftOption#74c34319 as nil" )
}
b .PutID (PremiumGiftOptionTypeID )
return p .EncodeBare (b )
}
func (p *PremiumGiftOption ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode premiumGiftOption#74c34319 as nil" )
}
p .SetFlags ()
if err := p .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode premiumGiftOption#74c34319: field flags: %w" , err )
}
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 *PremiumGiftOption ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode premiumGiftOption#74c34319 to nil" )
}
if err := b .ConsumeID (PremiumGiftOptionTypeID ); err != nil {
return fmt .Errorf ("unable to decode premiumGiftOption#74c34319: %w" , err )
}
return p .DecodeBare (b )
}
func (p *PremiumGiftOption ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode premiumGiftOption#74c34319 to nil" )
}
{
if err := p .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode premiumGiftOption#74c34319: field flags: %w" , err )
}
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftOption#74c34319: field months: %w" , err )
}
p .Months = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftOption#74c34319: field currency: %w" , err )
}
p .Currency = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftOption#74c34319: field amount: %w" , err )
}
p .Amount = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftOption#74c34319: 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 premiumGiftOption#74c34319: field store_product: %w" , err )
}
p .StoreProduct = value
}
return nil
}
func (p *PremiumGiftOption ) GetMonths () (value int ) {
if p == nil {
return
}
return p .Months
}
func (p *PremiumGiftOption ) GetCurrency () (value string ) {
if p == nil {
return
}
return p .Currency
}
func (p *PremiumGiftOption ) GetAmount () (value int64 ) {
if p == nil {
return
}
return p .Amount
}
func (p *PremiumGiftOption ) GetBotURL () (value string ) {
if p == nil {
return
}
return p .BotURL
}
func (p *PremiumGiftOption ) SetStoreProduct (value string ) {
p .Flags .Set (0 )
p .StoreProduct = value
}
func (p *PremiumGiftOption ) 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 .