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 PremiumGiftCodeOption struct {
Flags bin .Fields
Users int
Months int
StoreProduct string
StoreQuantity int
Currency string
Amount int64
}
const PremiumGiftCodeOptionTypeID = 0x257e962b
var (
_ bin .Encoder = &PremiumGiftCodeOption {}
_ bin .Decoder = &PremiumGiftCodeOption {}
_ bin .BareEncoder = &PremiumGiftCodeOption {}
_ bin .BareDecoder = &PremiumGiftCodeOption {}
)
func (p *PremiumGiftCodeOption ) Zero () bool {
if p == nil {
return true
}
if !(p .Flags .Zero ()) {
return false
}
if !(p .Users == 0 ) {
return false
}
if !(p .Months == 0 ) {
return false
}
if !(p .StoreProduct == "" ) {
return false
}
if !(p .StoreQuantity == 0 ) {
return false
}
if !(p .Currency == "" ) {
return false
}
if !(p .Amount == 0 ) {
return false
}
return true
}
func (p *PremiumGiftCodeOption ) String () string {
if p == nil {
return "PremiumGiftCodeOption(nil)"
}
type Alias PremiumGiftCodeOption
return fmt .Sprintf ("PremiumGiftCodeOption%+v" , Alias (*p ))
}
func (p *PremiumGiftCodeOption ) FillFrom (from interface {
GetUsers () (value int )
GetMonths () (value int )
GetStoreProduct () (value string , ok bool )
GetStoreQuantity () (value int , ok bool )
GetCurrency () (value string )
GetAmount () (value int64 )
}) {
p .Users = from .GetUsers ()
p .Months = from .GetMonths ()
if val , ok := from .GetStoreProduct (); ok {
p .StoreProduct = val
}
if val , ok := from .GetStoreQuantity (); ok {
p .StoreQuantity = val
}
p .Currency = from .GetCurrency ()
p .Amount = from .GetAmount ()
}
func (*PremiumGiftCodeOption ) TypeID () uint32 {
return PremiumGiftCodeOptionTypeID
}
func (*PremiumGiftCodeOption ) TypeName () string {
return "premiumGiftCodeOption"
}
func (p *PremiumGiftCodeOption ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "premiumGiftCodeOption" ,
ID : PremiumGiftCodeOptionTypeID ,
}
if p == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Users" ,
SchemaName : "users" ,
},
{
Name : "Months" ,
SchemaName : "months" ,
},
{
Name : "StoreProduct" ,
SchemaName : "store_product" ,
Null : !p .Flags .Has (0 ),
},
{
Name : "StoreQuantity" ,
SchemaName : "store_quantity" ,
Null : !p .Flags .Has (1 ),
},
{
Name : "Currency" ,
SchemaName : "currency" ,
},
{
Name : "Amount" ,
SchemaName : "amount" ,
},
}
return typ
}
func (p *PremiumGiftCodeOption ) SetFlags () {
if !(p .StoreProduct == "" ) {
p .Flags .Set (0 )
}
if !(p .StoreQuantity == 0 ) {
p .Flags .Set (1 )
}
}
func (p *PremiumGiftCodeOption ) Encode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode premiumGiftCodeOption#257e962b as nil" )
}
b .PutID (PremiumGiftCodeOptionTypeID )
return p .EncodeBare (b )
}
func (p *PremiumGiftCodeOption ) EncodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't encode premiumGiftCodeOption#257e962b as nil" )
}
p .SetFlags ()
if err := p .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode premiumGiftCodeOption#257e962b: field flags: %w" , err )
}
b .PutInt (p .Users )
b .PutInt (p .Months )
if p .Flags .Has (0 ) {
b .PutString (p .StoreProduct )
}
if p .Flags .Has (1 ) {
b .PutInt (p .StoreQuantity )
}
b .PutString (p .Currency )
b .PutLong (p .Amount )
return nil
}
func (p *PremiumGiftCodeOption ) Decode (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode premiumGiftCodeOption#257e962b to nil" )
}
if err := b .ConsumeID (PremiumGiftCodeOptionTypeID ); err != nil {
return fmt .Errorf ("unable to decode premiumGiftCodeOption#257e962b: %w" , err )
}
return p .DecodeBare (b )
}
func (p *PremiumGiftCodeOption ) DecodeBare (b *bin .Buffer ) error {
if p == nil {
return fmt .Errorf ("can't decode premiumGiftCodeOption#257e962b to nil" )
}
{
if err := p .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode premiumGiftCodeOption#257e962b: field flags: %w" , err )
}
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftCodeOption#257e962b: field users: %w" , err )
}
p .Users = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftCodeOption#257e962b: field months: %w" , err )
}
p .Months = value
}
if p .Flags .Has (0 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftCodeOption#257e962b: field store_product: %w" , err )
}
p .StoreProduct = value
}
if p .Flags .Has (1 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftCodeOption#257e962b: field store_quantity: %w" , err )
}
p .StoreQuantity = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftCodeOption#257e962b: field currency: %w" , err )
}
p .Currency = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode premiumGiftCodeOption#257e962b: field amount: %w" , err )
}
p .Amount = value
}
return nil
}
func (p *PremiumGiftCodeOption ) GetUsers () (value int ) {
if p == nil {
return
}
return p .Users
}
func (p *PremiumGiftCodeOption ) GetMonths () (value int ) {
if p == nil {
return
}
return p .Months
}
func (p *PremiumGiftCodeOption ) SetStoreProduct (value string ) {
p .Flags .Set (0 )
p .StoreProduct = value
}
func (p *PremiumGiftCodeOption ) GetStoreProduct () (value string , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (0 ) {
return value , false
}
return p .StoreProduct , true
}
func (p *PremiumGiftCodeOption ) SetStoreQuantity (value int ) {
p .Flags .Set (1 )
p .StoreQuantity = value
}
func (p *PremiumGiftCodeOption ) GetStoreQuantity () (value int , ok bool ) {
if p == nil {
return
}
if !p .Flags .Has (1 ) {
return value , false
}
return p .StoreQuantity , true
}
func (p *PremiumGiftCodeOption ) GetCurrency () (value string ) {
if p == nil {
return
}
return p .Currency
}
func (p *PremiumGiftCodeOption ) GetAmount () (value int64 ) {
if p == nil {
return
}
return p .Amount
}
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 .