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 PaymentsCheckedGiftCode struct {
Flags bin .Fields
ViaGiveaway bool
FromID PeerClass
GiveawayMsgID int
ToID int64
Date int
Months int
UsedDate int
Chats []ChatClass
Users []UserClass
}
const PaymentsCheckedGiftCodeTypeID = 0x284a1096
var (
_ bin .Encoder = &PaymentsCheckedGiftCode {}
_ bin .Decoder = &PaymentsCheckedGiftCode {}
_ bin .BareEncoder = &PaymentsCheckedGiftCode {}
_ bin .BareDecoder = &PaymentsCheckedGiftCode {}
)
func (c *PaymentsCheckedGiftCode ) Zero () bool {
if c == nil {
return true
}
if !(c .Flags .Zero ()) {
return false
}
if !(c .ViaGiveaway == false ) {
return false
}
if !(c .FromID == nil ) {
return false
}
if !(c .GiveawayMsgID == 0 ) {
return false
}
if !(c .ToID == 0 ) {
return false
}
if !(c .Date == 0 ) {
return false
}
if !(c .Months == 0 ) {
return false
}
if !(c .UsedDate == 0 ) {
return false
}
if !(c .Chats == nil ) {
return false
}
if !(c .Users == nil ) {
return false
}
return true
}
func (c *PaymentsCheckedGiftCode ) String () string {
if c == nil {
return "PaymentsCheckedGiftCode(nil)"
}
type Alias PaymentsCheckedGiftCode
return fmt .Sprintf ("PaymentsCheckedGiftCode%+v" , Alias (*c ))
}
func (c *PaymentsCheckedGiftCode ) FillFrom (from interface {
GetViaGiveaway () (value bool )
GetFromID () (value PeerClass , ok bool )
GetGiveawayMsgID () (value int , ok bool )
GetToID () (value int64 , ok bool )
GetDate () (value int )
GetMonths () (value int )
GetUsedDate () (value int , ok bool )
GetChats () (value []ChatClass )
GetUsers () (value []UserClass )
}) {
c .ViaGiveaway = from .GetViaGiveaway ()
if val , ok := from .GetFromID (); ok {
c .FromID = val
}
if val , ok := from .GetGiveawayMsgID (); ok {
c .GiveawayMsgID = val
}
if val , ok := from .GetToID (); ok {
c .ToID = val
}
c .Date = from .GetDate ()
c .Months = from .GetMonths ()
if val , ok := from .GetUsedDate (); ok {
c .UsedDate = val
}
c .Chats = from .GetChats ()
c .Users = from .GetUsers ()
}
func (*PaymentsCheckedGiftCode ) TypeID () uint32 {
return PaymentsCheckedGiftCodeTypeID
}
func (*PaymentsCheckedGiftCode ) TypeName () string {
return "payments.checkedGiftCode"
}
func (c *PaymentsCheckedGiftCode ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "payments.checkedGiftCode" ,
ID : PaymentsCheckedGiftCodeTypeID ,
}
if c == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "ViaGiveaway" ,
SchemaName : "via_giveaway" ,
Null : !c .Flags .Has (2 ),
},
{
Name : "FromID" ,
SchemaName : "from_id" ,
Null : !c .Flags .Has (4 ),
},
{
Name : "GiveawayMsgID" ,
SchemaName : "giveaway_msg_id" ,
Null : !c .Flags .Has (3 ),
},
{
Name : "ToID" ,
SchemaName : "to_id" ,
Null : !c .Flags .Has (0 ),
},
{
Name : "Date" ,
SchemaName : "date" ,
},
{
Name : "Months" ,
SchemaName : "months" ,
},
{
Name : "UsedDate" ,
SchemaName : "used_date" ,
Null : !c .Flags .Has (1 ),
},
{
Name : "Chats" ,
SchemaName : "chats" ,
},
{
Name : "Users" ,
SchemaName : "users" ,
},
}
return typ
}
func (c *PaymentsCheckedGiftCode ) SetFlags () {
if !(c .ViaGiveaway == false ) {
c .Flags .Set (2 )
}
if !(c .FromID == nil ) {
c .Flags .Set (4 )
}
if !(c .GiveawayMsgID == 0 ) {
c .Flags .Set (3 )
}
if !(c .ToID == 0 ) {
c .Flags .Set (0 )
}
if !(c .UsedDate == 0 ) {
c .Flags .Set (1 )
}
}
func (c *PaymentsCheckedGiftCode ) Encode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode payments.checkedGiftCode#284a1096 as nil" )
}
b .PutID (PaymentsCheckedGiftCodeTypeID )
return c .EncodeBare (b )
}
func (c *PaymentsCheckedGiftCode ) EncodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't encode payments.checkedGiftCode#284a1096 as nil" )
}
c .SetFlags ()
if err := c .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode payments.checkedGiftCode#284a1096: field flags: %w" , err )
}
if c .Flags .Has (4 ) {
if c .FromID == nil {
return fmt .Errorf ("unable to encode payments.checkedGiftCode#284a1096: field from_id is nil" )
}
if err := c .FromID .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode payments.checkedGiftCode#284a1096: field from_id: %w" , err )
}
}
if c .Flags .Has (3 ) {
b .PutInt (c .GiveawayMsgID )
}
if c .Flags .Has (0 ) {
b .PutLong (c .ToID )
}
b .PutInt (c .Date )
b .PutInt (c .Months )
if c .Flags .Has (1 ) {
b .PutInt (c .UsedDate )
}
b .PutVectorHeader (len (c .Chats ))
for idx , v := range c .Chats {
if v == nil {
return fmt .Errorf ("unable to encode payments.checkedGiftCode#284a1096: field chats element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode payments.checkedGiftCode#284a1096: field chats element with index %d: %w" , idx , err )
}
}
b .PutVectorHeader (len (c .Users ))
for idx , v := range c .Users {
if v == nil {
return fmt .Errorf ("unable to encode payments.checkedGiftCode#284a1096: field users element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode payments.checkedGiftCode#284a1096: field users element with index %d: %w" , idx , err )
}
}
return nil
}
func (c *PaymentsCheckedGiftCode ) Decode (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode payments.checkedGiftCode#284a1096 to nil" )
}
if err := b .ConsumeID (PaymentsCheckedGiftCodeTypeID ); err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: %w" , err )
}
return c .DecodeBare (b )
}
func (c *PaymentsCheckedGiftCode ) DecodeBare (b *bin .Buffer ) error {
if c == nil {
return fmt .Errorf ("can't decode payments.checkedGiftCode#284a1096 to nil" )
}
{
if err := c .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field flags: %w" , err )
}
}
c .ViaGiveaway = c .Flags .Has (2 )
if c .Flags .Has (4 ) {
value , err := DecodePeer (b )
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field from_id: %w" , err )
}
c .FromID = value
}
if c .Flags .Has (3 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field giveaway_msg_id: %w" , err )
}
c .GiveawayMsgID = value
}
if c .Flags .Has (0 ) {
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field to_id: %w" , err )
}
c .ToID = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field date: %w" , err )
}
c .Date = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field months: %w" , err )
}
c .Months = value
}
if c .Flags .Has (1 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field used_date: %w" , err )
}
c .UsedDate = value
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field chats: %w" , err )
}
if headerLen > 0 {
c .Chats = make ([]ChatClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeChat (b )
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field chats: %w" , err )
}
c .Chats = append (c .Chats , value )
}
}
{
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field users: %w" , err )
}
if headerLen > 0 {
c .Users = make ([]UserClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeUser (b )
if err != nil {
return fmt .Errorf ("unable to decode payments.checkedGiftCode#284a1096: field users: %w" , err )
}
c .Users = append (c .Users , value )
}
}
return nil
}
func (c *PaymentsCheckedGiftCode ) SetViaGiveaway (value bool ) {
if value {
c .Flags .Set (2 )
c .ViaGiveaway = true
} else {
c .Flags .Unset (2 )
c .ViaGiveaway = false
}
}
func (c *PaymentsCheckedGiftCode ) GetViaGiveaway () (value bool ) {
if c == nil {
return
}
return c .Flags .Has (2 )
}
func (c *PaymentsCheckedGiftCode ) SetFromID (value PeerClass ) {
c .Flags .Set (4 )
c .FromID = value
}
func (c *PaymentsCheckedGiftCode ) GetFromID () (value PeerClass , ok bool ) {
if c == nil {
return
}
if !c .Flags .Has (4 ) {
return value , false
}
return c .FromID , true
}
func (c *PaymentsCheckedGiftCode ) SetGiveawayMsgID (value int ) {
c .Flags .Set (3 )
c .GiveawayMsgID = value
}
func (c *PaymentsCheckedGiftCode ) GetGiveawayMsgID () (value int , ok bool ) {
if c == nil {
return
}
if !c .Flags .Has (3 ) {
return value , false
}
return c .GiveawayMsgID , true
}
func (c *PaymentsCheckedGiftCode ) SetToID (value int64 ) {
c .Flags .Set (0 )
c .ToID = value
}
func (c *PaymentsCheckedGiftCode ) GetToID () (value int64 , ok bool ) {
if c == nil {
return
}
if !c .Flags .Has (0 ) {
return value , false
}
return c .ToID , true
}
func (c *PaymentsCheckedGiftCode ) GetDate () (value int ) {
if c == nil {
return
}
return c .Date
}
func (c *PaymentsCheckedGiftCode ) GetMonths () (value int ) {
if c == nil {
return
}
return c .Months
}
func (c *PaymentsCheckedGiftCode ) SetUsedDate (value int ) {
c .Flags .Set (1 )
c .UsedDate = value
}
func (c *PaymentsCheckedGiftCode ) GetUsedDate () (value int , ok bool ) {
if c == nil {
return
}
if !c .Flags .Has (1 ) {
return value , false
}
return c .UsedDate , true
}
func (c *PaymentsCheckedGiftCode ) GetChats () (value []ChatClass ) {
if c == nil {
return
}
return c .Chats
}
func (c *PaymentsCheckedGiftCode ) GetUsers () (value []UserClass ) {
if c == nil {
return
}
return c .Users
}
func (c *PaymentsCheckedGiftCode ) MapChats () (value ChatClassArray ) {
return ChatClassArray (c .Chats )
}
func (c *PaymentsCheckedGiftCode ) MapUsers () (value UserClassArray ) {
return UserClassArray (c .Users )
}
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 .